Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: stacked histogram does not properly handle edgecolor and hatches #26718

Closed
Milestone
@marcelernst

Description

@marcelernst

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:
test_bugreport
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp