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

Ensure consistent split Violin color assignment #4650

Merged
merged 1 commit into from
Oct 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions holoviews/plotting/bokeh/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def _kde_data(self, element, el, key, split_dim, split_cats, **kwargs):
if len(split_cats) > 2:
raise ValueError(
'The number of categories for split violin plots cannot be '
'greater than 2! Found {0} categories: {1}'.format(
'greater than 2. Found {0} categories: {1}'.format(
len(split_cats), ', '.join(split_cats)))
el = el.add_dimension(repr(split_dim), len(el.kdims), all_cats)
kdes = univariate_kde(el, dimension=vdim.name, groupby=repr(split_dim), **kwargs)
Expand Down Expand Up @@ -545,12 +545,16 @@ def get_data(self, element, ranges, style):

kwargs = {'bandwidth': self.bandwidth, 'cut': self.cut}
mapping, data = {}, {}
kde_data, line_data, seg_data, bar_data, scatter_data = (defaultdict(list) for i in range(5))
kde_data, line_data, seg_data, bar_data, scatter_data = (
defaultdict(list) for i in range(5)
)
for i, (key, g) in enumerate(groups.items()):
key = decode_bytes(key)
if element.kdims:
key = tuple(d.pprint_value(k) for d, k in zip(element.kdims, key))
kde, line, segs, bars, scatter = self._kde_data(element, g, key, split_dim, split_cats, **kwargs)
kde, line, segs, bars, scatter = self._kde_data(
element, g, key, split_dim, split_cats, **kwargs
)
for k, v in segs.items():
seg_data[k] += v
for k, v in bars.items():
Expand Down Expand Up @@ -584,7 +588,7 @@ def get_data(self, element, ranges, style):
mapping['scatter_1'] = scatter_map

if split_dim:
factors = [str(v) for v in unique_iterator(split_dim.apply(element))]
factors = [str(v) for v in split_cats]
cmapper = self._get_colormapper(
split_dim, element, ranges, dict(style), name='violin_color_mapper',
group='violin', factors=factors)
Expand Down