List of colors not allowed when `hist = True`
The following code works and plots the densities for each of my Files.
colors = ['red', 'red', 'red', 'grey', 'grey', 'grey', 'green', 'green', 'green', 'blue', 'blue', 'blue']
fig, axes = joypy.joyplot(img_data_df,
by='File',
column='MinFeret',
color=colors,
bins=50,
overlap=0,
)
but when I plot the histograms:
fig, axes = joypy.joyplot(img_data_df,
by='File',
column='MinFeret',
color=colors,
bins=50,
overlap=0,
hist=True, # Produces error
)
matplotlib.hist() expects color to only be a single value. Which throws an error here: https://github.com/leotac/joypy/blob/fb74cb6c725199cca4f5260fdbc0a90ff579c7f3/joypy/joyplot.py#L465-L469
Traceback
ValueError Traceback (most recent call last) Cell In[11], line 10 7 f_group = get_group(f) 8 colors.append(palette[f_group]) ---> 10 fig, axes = joypy.joyplot(img_data_df, 11 by='File', 12 column='MinFeret', 13 color=colors, 14 hist=True, 15 bins=50, 16 overlap=0, 17 )
File ~/school/ivan_img_reanalysis/venv/lib/python3.10/site-packages/joypy/joyplot.py:241, in joyplot(data, column, by, grid, xlabelsize, xrot, ylabelsize, yrot, ax, figsize, hist, bins, fade, ylim, fill, linecolor, overlap, background, labels, xlabels, ylabels, range_style, x_range, title, colormap, color, normalize, floc, **kwds) 237 if any(len(subg)==0 for g in converted for subg in g): 238 warn("At least a column/group has no numeric values.") --> 241 return _joyplot(converted, labels=labels, sublabels=sublabels, 242 grid=grid, 243 xlabelsize=xlabelsize, xrot=xrot, ylabelsize=ylabelsize, yrot=yrot, 244 ax=ax, figsize=figsize, 245 hist=hist, bins=bins, 246 fade=fade, ylim=ylim, 247 fill=fill, linecolor=linecolor, 248 overlap=overlap, background=background, 249 xlabels=xlabels, 250 range_style=range_style, x_range=x_range, 251 title=title, 252 colormap=colormap, 253 color=color, 254 normalize=normalize, 255 floc=floc, 256 **kwds)
File ~/school/ivan_img_reanalysis/venv/lib/python3.10/site-packages/joypy/joyplot.py:467, in _joyplot(data, grid, labels, sublabels, xlabels, xlabelsize, xrot, ylabelsize, yrot, ax, figsize, hist, bins, fade, xlim, ylim, fill, linecolor, overlap, background, range_style, x_range, tails, title, legend, loc, colormap, color, normalize, floc, **kwargs) 463 num_subgroups = len(group) 465 if hist: 466 # matplotlib hist() already handles multiple subgroups in a histogram --> 467 a.hist(group, label=sublabels, bins=bins, color=color, 468 range=[min(global_x_range), max(global_x_range)], 469 edgecolor=linecolor, zorder=group_zorder, **kwargs) 470 else: 471 for j, subgroup in enumerate(group): 472 473 # Compute the x_range of the current plot
File ~/school/ivan_img_reanalysis/venv/lib/python3.10/site-packages/matplotlib/init.py:1465, in _preprocess_data.
File ~/school/ivan_img_reanalysis/venv/lib/python3.10/site-packages/matplotlib/axes/_axes.py:6818, in Axes.hist(self, x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs) 6816 colors = mcolors.to_rgba_array(color) 6817 if len(colors) != nx: -> 6818 raise ValueError(f"The 'color' keyword argument must have one " 6819 f"color per dataset, but {nx} datasets and " 6820 f"{len(colors)} colors were provided") 6822 hist_kwargs = dict() 6824 # if the bin_range is not given, compute without nan numpy 6825 # does not do this for us when guessing the range (but will 6826 # happily ignore nans when computing the histogram).
ValueError: The 'color' keyword argument must have one color per dataset, but 1 datasets and 12 colors were provided
I fixed it for myself by iterating through the subgroups and plotting the histograms separately: github.com/mrariden/joypy/blob/master/joypy/README.md?plain=1#L14
I can make a PR if this is a reasonable solution.