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

Commit2e7b3c6

Browse files
committed
[ENH] Vectorized Wedgeprops argument to pie
1 parent5093150 commit2e7b3c6

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

‎lib/matplotlib/axes/_axes.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
importcollections
12
importfunctools
23
importitertools
34
importlogging
@@ -3226,7 +3227,14 @@ def get_next_color():
32263227
slices= []
32273228
autotexts= []
32283229

3229-
forfrac,label,explinzip(x,labels,explode):
3230+
ifisinstance(wedgeprops,collections.abc.Sequence):
3231+
iflen(wedgeprops)!=len(x):
3232+
raiseValueError(f'wedgeprops length={len(wedgeprops)}'
3233+
f' and input length={len(x)} are not equal')
3234+
else:
3235+
wedgeprops=itertools.repeat(wedgeprops)
3236+
3237+
forfrac,label,expl,wpropsinzip(x,labels,explode,wedgeprops):
32303238
x,y=center
32313239
theta2= (theta1+frac)ifcounterclockelse (theta1-frac)
32323240
thetam=2*np.pi*0.5* (theta1+theta2)
@@ -3238,7 +3246,7 @@ def get_next_color():
32383246
facecolor=get_next_color(),
32393247
clip_on=False,
32403248
label=label)
3241-
w.set(**wedgeprops)
3249+
w.set(**wprops)
32423250
slices.append(w)
32433251
self.add_patch(w)
32443252

‎lib/matplotlib/tests/test_axes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5740,6 +5740,24 @@ def test_normalize_kwarg_pie():
57405740
assertabs(t2[0][-1].theta2-360.)>1e-3
57415741

57425742

5743+
deftest_pie_wedgeprops_error():
5744+
fig,ax=plt.subplots()
5745+
x= [0.3,0.3,0.1]
5746+
wedgeprops= [{'a':1}]
5747+
withpytest.raises(ValueError,match=r"length=1 .* length=3"):
5748+
ax.pie(x,wedgeprops=wedgeprops)
5749+
5750+
5751+
@check_figures_equal()
5752+
deftest_pie_multi_wedgeprops(fig_test,fig_ref):
5753+
x= [0.3,0.3,0.1]
5754+
wedgeprops= [{'hatch':'/'}, {'hatch':'+'}, {'hatch':'.'}]
5755+
fig_test.subplots().pie(x,wedgeprops=wedgeprops)
5756+
wedges,_=fig_ref.subplots().pie(x)
5757+
forw,wpinzip(wedges,wedgeprops):
5758+
w.set(**wp)
5759+
5760+
57435761
@image_comparison(['set_get_ticklabels.png'])
57445762
deftest_set_get_ticklabels():
57455763
# test issue 2246

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp