-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add support for arbitrary Vega-Lite plots #569
Comments
Hi @alexk101 , it is a little hidden in the docs, but it is possible to use custom vega templates in DVC as described in https://dvc.org/doc/command-reference/plots/templates#custom-templates . So, for your example, the custom template would look as follows: {
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": "<DVC_METRIC_DATA>"
},
"title": {"text": "<DVC_METRIC_TITLE>", "anchor": "middle"},
"encoding": {
"column": {"field": "category", "header": {"orient": "bottom"}},
"y": {"field": "<DVC_METRIC_Y>", "type": "quantitative"},
"x": {"field": "<DVC_METRIC_X>", "axis": null},
"color": {"field": "<DVC_METRIC_X>"}
},
"config": {"view": {"stroke": "transparent"}},
"mark": "bar"
} Assuming it is saved in from dvclive import Live
datapoints = [
{"category": "feedback", "group": "deck", "macroF1": 0.2513221334131033},
{
"category": "feedback",
"group": "deck shift",
"macroF1": 0.250825352553961
},
{
"category": "feedback",
"group": "earliest quint",
"macroF1": 0.204823556791436
},
{"category": "planning", "group": "deck", "macroF1": 0.2513221334131033},
{
"category": "planning",
"group": "deck shift",
"macroF1": 0.250825352553961
},
{
"category": "planning",
"group": "earliest quint",
"macroF1": 0.204823556791436
}
]
with Live(report=None) as live:
live.log_plot(
"custom_bar_plot",
datapoints,
x="group", y="macroF1", template="custom_template.json",
title="Classification Metrics"
) And the plot should be rendered correctly: $ dvc plots show |
Ah, I see. My understanding of the parameters and how they are injected was a little off. This solves my problem. Thanks, @daavoo ! And I see this other issue you have added and agree with your points there. |
@daavoo I seem to have found another sticking point for my work. Does DVC not support the 'spec' field for vega lite? I am trying to do something similar to what I previously posted, but using a faceted plot. {
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"repeat": ["quintile"],
"config": {"view": {"stroke": "transparent"}},
"spec": {
"title": {"text": "<DVC_METRIC_TITLE>", "anchor": "middle"},
"encoding": {
"column": {"field": "category", "header": {"orient": "bottom"}},
"row": {"field": "quintile", "title": "Quintile"},
"y": {"field": "<DVC_METRIC_Y>", "type": "quantitative"},
"x": {"field": "<DVC_METRIC_X>", "axis": null},
"color": {"field": "<DVC_METRIC_X>"}
},
"mark": "bar",
"data": {
"values": "<DVC_METRIC_DATA>"
}
}
} The structure of the plot is valid, as I have it displayed in the vega-lite editor here. When I try and plot this using DVCLive, it tells me that I am missing the '<DVC_METRIC_DATA'> anchor,
though I am clearly including it. Is this some kind of issue with how templates are parsed or am I missing something else? |
Sorry, that's obviously not the updated template 😄 . We will try to take a closer look as soon as we can. |
@dberenbaum Unfortunately still failing, though somewhere else now. Stacktrace:
DVC Doctor:
It seems to be getting stuck parsing the some part of the template that should be a dictionary, but is a string. |
I found where the problem in dvc-render is. I am opening a pull request for the change. Will update when I am done. |
Nice, thank you for finding that bug! Sorry, I guess it was me who was using the outdated version 🤦 . |
I think we can close this one and if something else comes up, open a new one here or in dvc-render. Thanks @alexk101 !! |
I am not entirely sure that this is a possible feature , as I feel it would have already been implemented if that were the case, but it would be nice to log any kind of vega-lite plot. Currently there exists the
log_plot
, but this is fairly limited by the requirements of DVC plot templates. For example, if I wanted to create a grouped bar plot, I could not with the current way in which values are injected.This is a live view of the above plot. It may be the case that it is more appropriate to submit this as an issue on DVC, and not DVCLive, but I will put it here for now.
The text was updated successfully, but these errors were encountered: