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

Commit01b27b0

Browse files
committed
Fix passing singleton sequence-type styles to hist
1 parent70d0bf7 commit01b27b0

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

‎lib/matplotlib/axes/_axes.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7193,15 +7193,26 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
71937193
labels= []iflabelisNoneelsenp.atleast_1d(np.asarray(label,str))
71947194

71957195
ifhisttype=="step":
7196-
edgecolors=itertools.cycle(np.atleast_1d(kwargs.get('edgecolor',
7197-
colors)))
7196+
ec=kwargs.get('edgecolor',colors)
71987197
else:
7199-
edgecolors=itertools.cycle(np.atleast_1d(kwargs.get("edgecolor",None)))
7198+
ec=kwargs.get('edgecolor',None)
7199+
ifecisNoneorcbook._str_lower_equal(ec,'none'):
7200+
edgecolors=itertools.repeat(ec)
7201+
else:
7202+
edgecolors=itertools.cycle(mcolors.to_rgba_array(ec))
7203+
7204+
fc=kwargs.get('facecolor',colors)
7205+
ifcbook._str_lower_equal(fc,'none'):
7206+
facecolors=itertools.repeat(fc)
7207+
else:
7208+
facecolors=itertools.cycle(mcolors.to_rgba_array(fc))
72007209

7201-
facecolors=itertools.cycle(np.atleast_1d(kwargs.get('facecolor',colors)))
72027210
hatches=itertools.cycle(np.atleast_1d(kwargs.get('hatch',None)))
72037211
linewidths=itertools.cycle(np.atleast_1d(kwargs.get('linewidth',None)))
7204-
linestyles=itertools.cycle(np.atleast_1d(kwargs.get('linestyle',None)))
7212+
if'linestyle'inkwargs:
7213+
linestyles=itertools.cycle(mlines._get_dash_patterns(kwargs['linestyle']))
7214+
else:
7215+
linestyles=itertools.repeat(None)
72057216

72067217
forpatch,lblinitertools.zip_longest(patches,labels):
72077218
ifnotpatch:

‎lib/matplotlib/collections.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -632,17 +632,8 @@ def set_linestyle(self, ls):
632632
':', '', (offset, on-off-seq)}. See `.Line2D.set_linestyle` for a
633633
complete description.
634634
"""
635-
try:
636-
dashes= [mlines._get_dash_pattern(ls)]
637-
exceptValueError:
638-
try:
639-
dashes= [mlines._get_dash_pattern(x)forxinls]
640-
exceptValueErroraserr:
641-
emsg=f'Do not know how to convert{ls!r} to dashes'
642-
raiseValueError(emsg)fromerr
643-
644635
# get the list of raw 'unscaled' dash patterns
645-
self._us_linestyles=dashes
636+
self._us_linestyles=mlines._get_dash_patterns(ls)
646637

647638
# broadcast and scale the lw and dash patterns
648639
self._linewidths,self._linestyles=self._bcast_lwls(

‎lib/matplotlib/lines.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ def _get_dash_pattern(style):
6060
returnoffset,dashes
6161

6262

63+
def_get_dash_patterns(styles):
64+
"""Convert linestyle or sequence of linestyles to list of dash patterns."""
65+
try:
66+
patterns= [_get_dash_pattern(styles)]
67+
exceptValueError:
68+
try:
69+
patterns= [_get_dash_pattern(x)forxinstyles]
70+
exceptValueErroraserr:
71+
emsg=f'Do not know how to convert{styles!r} to dashes'
72+
raiseValueError(emsg)fromerr
73+
74+
returnpatterns
75+
76+
6377
def_get_inverse_dash_pattern(offset,dashes):
6478
"""Return the inverse of the given dash pattern, for filling the gaps."""
6579
# Define the inverse pattern by moving the last gap to the start of the

‎lib/matplotlib/tests/test_axes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4831,6 +4831,27 @@ def test_hist_vectorized_params(fig_test, fig_ref, kwargs):
48314831
zorder=(len(xs)-i)/2)
48324832

48334833

4834+
deftest_hist_sequence_type_styles():
4835+
facecolor= ('r',0.5)
4836+
edgecolor= [0.5,0.5,0.5]
4837+
linestyle= (0, (1,1))
4838+
4839+
arr=np.random.uniform(size=50)
4840+
_,_,bars=plt.hist(arr,facecolor=facecolor,edgecolor=edgecolor,
4841+
linestyle=linestyle)
4842+
assertmcolors.same_color(bars[0].get_facecolor(),facecolor)
4843+
assertmcolors.same_color(bars[0].get_edgecolor(),edgecolor)
4844+
assertbars[0].get_linestyle()==linestyle
4845+
4846+
4847+
deftest_hist_color_none():
4848+
arr=np.random.uniform(size=50)
4849+
# No edgecolor is the default but check that it can be explicitly passed.
4850+
_,_,bars=plt.hist(arr,facecolor='none',edgecolor='none')
4851+
assertbars[0].get_facecolor(), (0,0,0,0)
4852+
assertbars[0].get_edgecolor(), (0,0,0,0)
4853+
4854+
48344855
@pytest.mark.parametrize('kwargs, patch_face, patch_edge',
48354856
# 'C0'(blue) stands for the first color of the
48364857
# default color cycle as well as the patch.facecolor rcParam

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp