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

Coordinate label of a multi-element chart from an xarray Dataset lacks long name and units #816

Closed
stanwest opened this issue Aug 3, 2022 · 0 comments · Fixed by #930
Closed
Labels
type: enhancement New feature or request
Milestone

Comments

@stanwest
Copy link

stanwest commented Aug 3, 2022

Relevant software versions are collapsed here.
# Name                    Version                   Build  Channel
bokeh                     2.4.3            py39haa95532_0
holoviews                 1.15.0           py39haa95532_0
hvplot                    0.8.0            py39haa95532_0
python                    3.9.12               h6244533_0
xarray                    2022.6.0           pyhd8ed1ab_1    conda-forge

Given an xarray.Dataset that contains multiple data variables and a coordinate with "long_name" and/or "units" attributes, a multi-element plot created from that dataset labels the coordinate with only the coordinate's name instead of its long name and units:

In [1]: import holoviews, hvplot.xarray, xarray

In [2]: dset = xarray.Dataset(
   ...:     {"u": ("t", [1, 3]), "v": ("t", [4, 2])},
   ...:     coords={"t": ("t", [0, 1], {"long_name": "time", "units": "s"})},
   ...: )

In [3]: ndoverlay = dset.hvplot.line()

In [4]: ndoverlay.ddims[0]
Out[4]: Dimension('t')

In [5]: holoviews.render(ndoverlay).xaxis.axis_label
Out[5]: 't'

The same is true for an NdLayout returned by dset.hvplot.line(subplots=True).

In contrast, a single-element plot created from one data variable has coordinates labeled with the long name and units:

In [6]: curve = dset["u"].hvplot.line()

In [7]: curve.kdims[0]
Out[7]: Dimension('t', label='time', unit='s')

In [8]: holoviews.render(curve).xaxis.axis_label
Out[8]: 'time (s)'

Similarly, a single-element bar plot dset.hvplot.bar() of both variables in the dataset honors the long name and units:

In [9]: dset.hvplot.bar().kdims[0]
Out[9]: Dimension('t', label='time', unit='s')

A possible cause is that, whereas the HoloViewsConverter.single_chart and other plot methods apply the long name and units stored in self._redim by calling the redim(**self._redim) method on the chart [code], the HoloViewsConverter.chart method lacks such a call for the multi-element case [code]. Could the call be included in the HoloViewsConverter.chart method?

To work around the difference, the user may re-dimension the returned overlay, although converting the attributes from the dataset is a bit verbose:

In [10]: labeled_ndoverlay = ndoverlay.redim(**{"t": {
    ...:     hname: dset["t"].attrs[xname]
    ...:     for hname, xname in [("label", "long_name"), ("unit", "units")]
    ...: }})

In [11]: labeled_ndoverlay.ddims[0]
Out[11]: Dimension('t', label='time', unit='s')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants