Skip to content

Commit 011d91b

Browse files
Allow customzing the trackio color palette (#339)
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
1 parent 4fd841f commit 011d91b

7 files changed

Lines changed: 82 additions & 10 deletions

File tree

.changeset/thin-ducks-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trackio": minor
3+
---
4+
5+
feat:Allow customzing the trackio color palette

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222

2323
`trackio` is a lightweight, free experiment tracking Python library built by Hugging Face 🤗.
2424

25-
![Screen Recording 2025-07-28 at 5 26 32 PM](https://github.com/user-attachments/assets/f3eac49e-d8ee-4fc0-b1ca-aedfc6d6fae1)
25+
![Screen Recording 2025-11-06 at 5 34 50 PM](https://github.com/user-attachments/assets/8c9c1b96-f17a-401c-83a4-26ac754f89c7)
26+
2627

2728
- **API compatible** with `wandb.init`, `wandb.log`, and `wandb.finish`. Drop-in replacement: just
2829

docs/source/environment_variables.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ export TRACKIO_THEME="gstaff/xkcd"
5959
export TRACKIO_THEME="ParityError/Anime"
6060
```
6161

62+
### `TRACKIO_COLOR_PALETTE`
63+
64+
Customizes the color palette used for plot lines in the Trackio dashboard. The value should be a comma-separated list of hex color codes. These colors will be cycled through when plotting multiple runs.
65+
66+
```bash
67+
export TRACKIO_COLOR_PALETTE="#FF0000,#00FF00,#0000FF,#FFFF00,#FF00FF,#00FFFF"
68+
```
69+
70+
**Default palette:**
71+
`#A8769B, #E89957, #3B82F6, #10B981, #EF4444, #8B5CF6, #14B8A6, #F59E0B, #EC4899, #06B6D4`
72+
6273
### `TRACKIO_TABLE_TRUNCATE_LENGTH`
6374

6475
Controls the maximum length of string values displayed in table cells before they are truncated. When a cell value exceeds this length, it will be truncated with an expandable element that allows viewing the full text. Defaults to `250` characters.

docs/source/launch.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,31 @@ trackio.show(theme="soft")
7171

7272
To see the available themes, check out the [themes gallery](https://huggingface.co/spaces/gradio/theme-gallery).
7373

74+
## Customizing Plot Colors
75+
76+
You can customize the color palette used for plot lines by providing a `color_palette` argument. This is useful if you want to match your organization's branding or have specific color preferences.
77+
78+
<hfoptions id="language">
79+
<hfoption id="Shell">
80+
81+
```sh
82+
trackio show --color-palette "#FF0000,#00FF00,#0000FF"
83+
```
84+
85+
</hfoption>
86+
<hfoption id="Python">
87+
88+
```py
89+
import trackio
90+
91+
trackio.show(color_palette=["#FF0000", "#00FF00", "#0000FF"])
92+
```
93+
94+
</hfoption>
95+
</hfoptions>
96+
97+
The colors will be cycled through when displaying multiple runs. You can provide as many or as few colors as you like.
98+
7499
## Launching a Dashboard in Jupyter Notebooks
75100

76101
You can also launch the dashboard directly within a Jupyter Notebook. Just use the same command as above:

trackio/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ def show(
311311
project: str | None = None,
312312
theme: str | ThemeClass | None = None,
313313
mcp_server: bool | None = None,
314+
color_palette: list[str] | None = None,
314315
*,
315316
open_browser: bool = True,
316317
block_thread: bool | None = None,
@@ -333,6 +334,11 @@ def show(
333334
functions will be added as MCP tools. If `None` (default behavior), then the
334335
`GRADIO_MCP_SERVER` environment variable will be used to determine if the
335336
MCP server should be enabled (which is `"True"` on Hugging Face Spaces).
337+
color_palette (`list[str]`, *optional*):
338+
A list of hex color codes to use for plot lines. If not provided, the
339+
`TRACKIO_COLOR_PALETTE` environment variable will be used (comma-separated
340+
hex codes), or if that is not set, the default color palette will be used.
341+
Example: `['#FF0000', '#00FF00', '#0000FF']`
336342
open_browser (`bool`, *optional*, defaults to `True`):
337343
If `True` and not in a notebook, a new browser tab will be opened with the dashboard.
338344
If `False`, the browser will not be opened.
@@ -347,6 +353,9 @@ def show(
347353
`share_url`: The public share URL of the dashboard.
348354
`full_url`: The full URL of the dashboard including the write token (will use the public share URL if launched publicly, otherwise the local URL).
349355
"""
356+
if color_palette is not None:
357+
os.environ["TRACKIO_COLOR_PALETTE"] = ",".join(color_palette)
358+
350359
theme = theme or os.environ.get("TRACKIO_THEME", DEFAULT_THEME)
351360

352361
if theme != DEFAULT_THEME:

trackio/cli.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@ def main():
2424
action="store_true",
2525
help="Enable MCP server functionality. The Trackio dashboard will be set up as an MCP server and certain functions will be exposed as MCP tools.",
2626
)
27+
ui_parser.add_argument(
28+
"--color-palette",
29+
required=False,
30+
help="Comma-separated list of hex color codes for plot lines (e.g. '#FF0000,#00FF00,#0000FF'). If not provided, the TRACKIO_COLOR_PALETTE environment variable will be used, or the default palette if not set.",
31+
)
2732

2833
args = parser.parse_args()
2934

3035
if args.command == "show":
31-
show(args.project, args.theme, args.mcp_server)
36+
color_palette = None
37+
if args.color_palette:
38+
color_palette = [color.strip() for color in args.color_palette.split(",")]
39+
show(args.project, args.theme, args.mcp_server, color_palette)
3240
else:
3341
parser.print_help()
3442

trackio/utils.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -465,26 +465,39 @@ def format_timestamp(timestamp_str):
465465
return "Unknown"
466466

467467

468-
COLOR_PALETTE = [
468+
DEFAULT_COLOR_PALETTE = [
469+
"#A8769B",
470+
"#E89957",
469471
"#3B82F6",
470-
"#EF4444",
471472
"#10B981",
472-
"#F59E0B",
473+
"#EF4444",
473474
"#8B5CF6",
475+
"#14B8A6",
476+
"#F59E0B",
474477
"#EC4899",
475478
"#06B6D4",
476-
"#84CC16",
477-
"#F97316",
478-
"#6366F1",
479479
]
480480

481481

482-
def get_color_mapping(runs: list[str], smoothing: bool) -> dict[str, str]:
482+
def get_color_palette() -> list[str]:
483+
"""Get the color palette from environment variable or use default."""
484+
env_palette = os.environ.get("TRACKIO_COLOR_PALETTE")
485+
if env_palette:
486+
return [color.strip() for color in env_palette.split(",")]
487+
return DEFAULT_COLOR_PALETTE
488+
489+
490+
def get_color_mapping(
491+
runs: list[str], smoothing: bool, color_palette: list[str] | None = None
492+
) -> dict[str, str]:
483493
"""Generate color mapping for runs, with transparency for original data when smoothing is enabled."""
494+
if color_palette is None:
495+
color_palette = get_color_palette()
496+
484497
color_map = {}
485498

486499
for i, run in enumerate(runs):
487-
base_color = COLOR_PALETTE[i % len(COLOR_PALETTE)]
500+
base_color = color_palette[i % len(color_palette)]
488501

489502
if smoothing:
490503
color_map[run] = base_color + "4D"

0 commit comments

Comments
 (0)