Replies: 4 comments
-
Using holoviews without the hv.Points(df, ["x", "y"], ['cat']).opts(color='cat') |
Beta Was this translation helpful? Give feedback.
-
This is not exactly right I think, HoloViews seems to just cycle through a default set of colors (blue, red, gold, etc.) defined here: N = 20
data = {'x': range(N), 'y': range(N), 'cat': [f'cat{i}' for i in range(N)]}
df2 = pd.DataFrame(data)
points = hv.Points(df2, ["x", "y"], ['cat'])
points.groupby('cat', hv.NdOverlay).opts(hv.opts.Points(size=5)).opts(width=700, legend_position='right', legend_cols=2)
Yep it looks like HoloViews just defaults to a linear colormap in this case, the style mapping user guide shows how to set a a categorical colormap in this case. import holoviews as hv
import hvplot.pandas
import pandas as pd
import numpy as np
N_POINTS_PER_GROUP = 1_000
GRID_DIM = 3
cat_k = 0
groups = []
for i in range(GRID_DIM):
for j in range(GRID_DIM):
groups.append((j, i, 0.25, f'cat{cat_k}'))
cat_k += 1
dists = [
pd.DataFrame(dict(x=np.random.normal(x, s, N_POINTS_PER_GROUP), y=np.random.normal(y, s, N_POINTS_PER_GROUP), cat=cat))
for x, y, s, cat in groups
]
df = pd.concat(dists, ignore_index=True)
df.hvplot.points(by='cat').opts(legend_cols=2) Internally, this is equivalent to: points = hv.Points(df, ["x", "y"], ['cat'])
points.groupby('cat', hv.NdOverlay).opts(hv.opts.Points(size=5)).opts(width=700, legend_position='right') The two plots above from hvPlot and HoloViews use the default HoloViews cycle.
df.hvplot.points(by='cat', datashade=True, dynspread=True, threshold=1) hvPlot uses
df.hvplot.points(color='cat').opts(legend_cols=8) # had to set a weird value for legend_cols... hvPlot uses hv.Points(df, ["x", "y"], ['cat']).opts(color='cat', legend_position='right', width=700, size=5, legend_cols=8) The hvPlot styling can be reproduced with: import colorcet as cc
hv.Points(df, ["x", "y"], ['cat']).opts(color='cat', legend_position='right', width=700, size=5, cmap=cc.palette['glasbey_category10'], legend_cols=8) The two categorical colormaps ❓ In fact, I don't know if the base color cycle of HoloViews is ad-hoc or comes from a reference color set? For reference, |
Beta Was this translation helpful? Give feedback.
-
From the above:
|
Beta Was this translation helpful? Give feedback.
-
Thank you for the clarification @maximlt. However, there is a sort of disconnect in my head that happens when you do points = hv.Points(df, ['x', 'y'])
points.opts(color='cat') for example and get a plot like this: versus when you do: points.opts(color='cat', cmap='glasbey_hv') which is equivalent to points.groupby('cat', hv.NdOverlay) and get a plot like this: This seems to imply (I don't know if I'm correct) that the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem? Please describe.
This is not a problem per se, but rather an observation which was raised on the discord channel: the default categorical colormaps in HoloViews and hvPlot do not match.
Describe the solution you’d like
I propose changing the default categorical colormap in hvPlot to
glasbey_hv
, which is currently used in HoloViews. My reasoning is as follows:hvPlot is often promoted as a high-level, more user-friendly alternative to HoloViews. For users moving from HoloViews to hvPlot, it would be beneficial to maintain certain features that enhance the user experience. By using the same default categorical colormap, we can create a more seamless transition and avoid the need for users to manually adjust the colormap to preserve their familiar visual settings.
Describe alternatives you’ve considered
Additional context
Here's a visual representation of the differences:
Beta Was this translation helpful? Give feedback.
All reactions