-
-
Notifications
You must be signed in to change notification settings - Fork 99
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 a title to xarray plots with scalar coords #659
Conversation
Whenever threre's no groupby or grid. The title is generated using xarray's api. It describes the coords that have a size of 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!!
Looks good. Could use some tests and also a reproducible example here in the PR's markdown.
This is part of their private API but this code hasn't changed in years.
Seems ok; if that interface does change I guess we could copy that code (and its associated license) in here, but for now at least it seems like a better bet that if xarray changes how it constructa those titles, we'd want to inherit those changes, and so it seems better to reply on the private API than to copy it here.
If the data has more than two dimensions it will default to a histogram without providing it further hints. In that case xarray.plot() just sets 'Histogram' as a title, while hvplot() will set the informative title (e.g. lon = 250).
The hvPlot behavior sounds more useful to me; feel free to propose that xarray change to match!
Whenever widgets are generated to explore the data (groupby op) the title is not changed, it is a title generated by holoviews that is in sync with the widget's values and displays them
Makes sense. When there are widgets, it's important to be able to see those widget values reflected in the title, so that we can be sure the plot actually does reflect the current widget settings. And if there are e.g. many, many dimensions but only a couple of widgets, we'd want the widget values in the title (as that's what's being explored), not the long list of other static dimension values. When there are no widgets, the only informative thing is the list of other static dimension values (long or not), so it seems reasonable to display that as a default. So I think I agree with this behavior, though I suppose I'd have to see how it worked in realistic situations to be sure my intuition is correct.
Co-authored-by: James A. Bednar <jbednar@users.noreply.github.com>
I'll add a few tests and will edit the PR's message with an example.
Yes I'll open an issue on their side. I also noticed that their code to format numbers actually doesn't work.
Yes I agree with you, it's important to have the widgets values reflected in the title, even if it's a little redundant. |
Fixes #656
Plots based on xarray objects that have scalar coords (e.g.
da.isel(lon=0)
) will get an informative title as one would get with xarray.plot() API. The generated title is equal to xarray's title since internally xarray's formatting utilities are used. This is part of their private API but this code hasn't changed in years.There are a couple of differences with xarray:
'Histogram'
as a title, while hvplot() will set the informative title (e.g.lon = 250
).