Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3664c83

Browse files
authored
Merge pull request #10943 from ImportanceOfBeingErnest/update-pie-textprops
Allow pie textprops to take alignment and rotation arguments
2 parents d9b5b4e + 0388083 commit 3664c83

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,13 +2705,13 @@ def get_next_color():
27052705
if rotatelabels:
27062706
label_alignment_v = yt > 0 and 'bottom' or 'top'
27072707
label_rotation = np.rad2deg(thetam) + (0 if xt > 0 else 180)
2708-
2709-
t = self.text(xt, yt, label,
2710-
size=rcParams['xtick.labelsize'],
2711-
horizontalalignment=label_alignment_h,
2708+
props = dict(horizontalalignment=label_alignment_h,
27122709
verticalalignment=label_alignment_v,
27132710
rotation=label_rotation,
2714-
**textprops)
2711+
size=rcParams['xtick.labelsize'])
2712+
props.update(textprops)
2713+
2714+
t = self.text(xt, yt, label, **props)
27152715

27162716
texts.append(t)
27172717

@@ -2726,10 +2726,10 @@ def get_next_color():
27262726
raise TypeError(
27272727
'autopct must be callable or a format string')
27282728

2729-
t = self.text(xt, yt, s,
2730-
horizontalalignment='center',
2731-
verticalalignment='center',
2732-
**textprops)
2729+
props = dict(horizontalalignment='center',
2730+
verticalalignment='center')
2731+
props.update(textprops)
2732+
t = self.text(xt, yt, s, **props)
27332733

27342734
autotexts.append(t)
27352735

lib/matplotlib/tests/test_axes.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4678,6 +4678,28 @@ def test_pie_rotatelabels_true():
46784678
plt.axis('equal')
46794679

46804680

4681+
def test_pie_textprops():
4682+
data = [23, 34, 45]
4683+
labels = ["Long name 1", "Long name 2", "Long name 3"]
4684+
4685+
textprops = dict(horizontalalignment="center",
4686+
verticalalignment="top",
4687+
rotation=90,
4688+
rotation_mode="anchor",
4689+
size=12, color="red")
4690+
4691+
_, texts, autopct = plt.gca().pie(data, labels=labels, autopct='%.2f',
4692+
textprops=textprops)
4693+
for labels in [texts, autopct]:
4694+
for tx in labels:
4695+
assert tx.get_ha() == textprops["horizontalalignment"]
4696+
assert tx.get_va() == textprops["verticalalignment"]
4697+
assert tx.get_rotation() == textprops["rotation"]
4698+
assert tx.get_rotation_mode() == textprops["rotation_mode"]
4699+
assert tx.get_size() == textprops["size"]
4700+
assert tx.get_color() == textprops["color"]
4701+
4702+
46814703
@image_comparison(baseline_images=['set_get_ticklabels'], extensions=['png'])
46824704
def test_set_get_ticklabels():
46834705
# test issue 2246

0 commit comments

Comments
 (0)