Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support lists for log_plot y val #837

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/dvclive/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def log_plot(
name: str,
datapoints: Union[pd.DataFrame, np.ndarray, List[Dict]],
x: str,
y: str,
y: Union[str, list[str]],
template: Optional[str] = "linear",
title: Optional[str] = None,
x_label: Optional[str] = None,
Expand All @@ -579,7 +579,8 @@ def log_plot(
datapoints (pd.DataFrame | np.ndarray | List[Dict]): Pandas DataFrame, Numpy
Array or List of dictionaries containing the data for the plot.
x (str): name of the key (present in the dictionaries) to use as the x axis.
y (str): name of the key (present in the dictionaries) to use the y axis.
y (str | list[str]): name of the key or keys (present in the
dictionaries) to use the y axis.
template (str): name of the `DVC plots template` to use. Defaults to
`"linear"`.
title (str): title to be displayed. Defaults to
Expand Down
4 changes: 2 additions & 2 deletions src/dvclive/plots/custom.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Optional
from typing import Optional, Union

from dvclive.serialize import dump_json

Expand All @@ -15,7 +15,7 @@ def __init__(
name: str,
output_folder: str,
x: str,
y: str,
y: Union[str, list[str]],
template: Optional[str],
title: Optional[str] = None,
x_label: Optional[str] = None,
Expand Down
27 changes: 27 additions & 0 deletions tests/plots/test_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,30 @@ def test_log_custom_plot(tmp_dir):
"x_label": "x_label",
"y_label": "y_label",
}


def test_log_custom_plot_multi_y(tmp_dir):
live = Live()
out = tmp_dir / live.plots_dir / CustomPlot.subfolder

datapoints = [{"x": 1, "y1": 2, "y2": 3}, {"x": 4, "y1": 5, "y2": 6}]
live.log_plot(
"custom_linear",
datapoints,
x="x",
y=["y1", "y2"],
template="linear",
title="custom_title",
x_label="x_label",
y_label="y_label",
)

assert json.loads((out / "custom_linear.json").read_text()) == datapoints
assert live._plots["custom_linear"].plot_config == {
"template": "linear",
"title": "custom_title",
"x": "x",
"y": ["y1", "y2"],
"x_label": "x_label",
"y_label": "y_label",
}
Loading