iterative / dvc-render

Library for rendering DVC plots
http://docs.iterative.ai/dvc-render/
Apache License 2.0
6 stars 5 forks source link

Set xlim/ylim in plot #147

Open dberenbaum opened 10 months ago

dberenbaum commented 10 months ago

See slack thread. It would be useful to have a way to set or adjust the min and max values of the axes.

dberenbaum commented 10 months ago

Found https://stackoverflow.com/questions/73404562/can-i-set-a-dynamic-axis-value-using-vegalite. It looks possible but messy mainly because there's no easy way to get sane defaults.

Technically, you can setup dynamic limits easily. See this diff to add it to the linear template:

$ diff linear.json lims.json
18a19,42
>     },
>     {
>       "name": "xmin",
>       "bind": {
>         "input": "number"
>       }
>     },
>     {
>       "name": "xmax",
>       "bind": {
>         "input": "number"
>       }
>     },
>     {
>       "name": "ymin",
>       "bind": {
>         "input": "number"
>       }
>     },
>     {
>       "name": "ymax",
>       "bind": {
>         "input": "number"
>       }
25c49,52
<       "title": "<DVC_METRIC_X_LABEL>"
---
>       "title": "<DVC_METRIC_X_LABEL>",
>       "scale": {
>           "domain": {"expr": "[xmin, xmax]"}
>       }
57c84,85
<             "zero": false
---
>             "zero": false,
>             "domain": {"expr": "[ymin, ymax]"}

However, the plots will show as blank until you set the axis values:

Screenshot 2023-12-11 at 1 58 52 PM

To avoid this, we need to recalculate default axis limits, which requires doing a transform to calculate the extent of the data and adding it to every row in the data.