Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
When using stacked histogram in matplotlib 3.7.2 the functionality of hatch and edgecolor is broken. It simply gives an error if trying to define either a separate edgecolor or hatch value for the stacked parts of the histogram.
Code for reproduction
importmatplotlib.pyplotaspltimportnumpyasnpplt.hist([np.random.uniform(size=100),np.random.uniform(size=50)],stacked=True,color=["C0","C1"],edgecolor='black',hatch=["/","."],linewidth=1,fill=True,density=False, )
Actual outcome
Traceback (most recent call last):
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3460, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
plt.hist([np.random.uniform(size=100), np.random.uniform(size=50)],
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/pyplot.py", line 2645, in hist
return gca().hist(
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/init.py", line 1446, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/axes/_axes.py", line 6944, in hist
p._internal_update(kwargs)
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/artist.py", line 1223, in _internal_update
return self._update_props(
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/artist.py", line 1199, in _update_props
ret.append(func(v))
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/patches.py", line 525, in set_hatch
mhatch._validate_hatch_pattern(hatch)
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/hatch.py", line 188, in _validate_hatch_pattern
invalids = ''.join(sorted(invalids))
TypeError: sequence item 0: expected str instance, NoneType found
While using different edgecolors for the stacked part with
plt.hist([np.random.uniform(size=100), np.random.uniform(size=50)], stacked=True, color=["C0", "C1"], edgecolor=["C2", "C3"], hatch="/", linewidth=1, fill=True, density=False, )
delivers the error
Traceback (most recent call last):
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3460, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
plt.hist([np.random.uniform(size=100), np.random.uniform(size=50)],
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/pyplot.py", line 2645, in hist
return gca().hist(
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/init.py", line 1446, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/axes/_axes.py", line 6944, in hist
p._internal_update(kwargs)
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/artist.py", line 1223, in _internal_update
return self._update_props(
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/artist.py", line 1199, in _update_props
ret.append(func(v))
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/patches.py", line 341, in set_edgecolor
self._set_edgecolor(color)
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/patches.py", line 327, in _set_edgecolor
self._edgecolor = colors.to_rgba(color, self._alpha)
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/colors.py", line 299, in to_rgba
rgba = _to_rgba_no_colorcycle(c, alpha)
File "/opt/anaconda3/envs/code/lib/python3.10/site-packages/matplotlib/colors.py", line 383, in _to_rgba_no_colorcycle
raise ValueError("RGBA sequence should have length 3 or 4")
ValueError: RGBA sequence should have length 3 or 4
It seems to interpret the list ofedgecolor
["C2", "C3"] as one color, although it is able to manage similar input forcolor
.
Expected outcome
It should look similar to the following example, except that the top orange part should have dots and not slanted lines:
The code used to generate this plot:
import matplotlib.pyplot as pltimport numpy as npplt.hist([np.random.uniform(size=100), np.random.uniform(size=50)], stacked=True, color=["C0", "C1"], edgecolor='black', hatch="/", linewidth=1, fill=True, density=False, )
In case of the second example it should habe two different edgecolors for the first and second part of the stacked histogram.
Additional information
No response
Operating system
MacOSX
Matplotlib Version
3.7.2
Matplotlib Backend
MacOSX
Python version
3.10.0
Jupyter version
No response
Installation
conda