Skip to content

Commit

Permalink
fix getting the color data
Browse files Browse the repository at this point in the history
  • Loading branch information
maximlt committed Jul 19, 2024
1 parent aa8b29a commit 24dd4c7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,11 @@ def _process_symmetric(self, symmetric, clim, check_symmetric_max):
return False

elif self._color_dim:
data = self.data[self._color_dim]
data = (
self.data[self._color_dim]
if self._color_dim in self.data.columns
else self.data.index.get_level_values(self._color_dim)
)
else:
return

Expand Down
24 changes: 24 additions & 0 deletions hvplot/tests/teststatplots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import numpy as np
import pandas as pd
import xarray as xr

from holoviews import Store

import hvplot.xarray # noqa: F401


def test_violin_from_xarray_with_by_and_color():
latitudes = np.linspace(-90, 90, 180)
longitudes = np.linspace(-180, 180, 360)
times = pd.date_range('2023-01-01', periods=365, freq='D')
data = np.random.random((365, 180, 360))
da = xr.DataArray(
data,
coords={'time': times, 'lat': latitudes, 'lon': longitudes},
dims=['time', 'lat', 'lon'],
name='temperature',
)
plot = da.hvplot.violin(y='temperature', by='lat', color='lat')
assert plot.kdims == ['lat']
opts = Store.lookup_options('bokeh', plot, 'style')
assert opts.kwargs['violin_fill_color'] == 'lat'

0 comments on commit 24dd4c7

Please sign in to comment.