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

Skip to content

Commit 8328e2c

Browse files
update-pie-textprops
1 parent c29d9b2 commit 8328e2c

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,13 +2749,13 @@ def get_next_color():
27492749
if rotatelabels:
27502750
label_alignment_v = yt > 0 and 'bottom' or 'top'
27512751
label_rotation = np.rad2deg(thetam) + (0 if xt > 0 else 180)
2752+
props = dict(horizontalalignment = label_alignment_h,
2753+
verticalalignment = label_alignment_v,
2754+
rotation = label_rotation,
2755+
size = rcParams['xtick.labelsize'])
2756+
props.update(textprops)
27522757

2753-
t = self.text(xt, yt, label,
2754-
size=rcParams['xtick.labelsize'],
2755-
horizontalalignment=label_alignment_h,
2756-
verticalalignment=label_alignment_v,
2757-
rotation=label_rotation,
2758-
**textprops)
2758+
t = self.text(xt, yt, label, **props)
27592759

27602760
texts.append(t)
27612761

lib/matplotlib/tests/test_axes.py

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

46684668

4669+
def test_pie_textprops():
4670+
data = [23,34,45]
4671+
labels=["Long name 1", "Long name 2", "Long name 3"]
4672+
4673+
textprops = dict(horizontalalignment="center",
4674+
verticalalignment="top",
4675+
rotation=90,
4676+
rotation_mode="anchor",
4677+
size=12, color="red")
4678+
4679+
_, texts, autopct = plt.gca().pie(data, labels=labels, autopct='%.2f',
4680+
textprops=textprops)
4681+
for labels in [texts,autopct]:
4682+
for tx in labels:
4683+
assert tx.get_ha() == textprops["horizontalalignment"]
4684+
assert tx.get_va() == textprops["verticalalignment"]
4685+
assert tx.get_rotation() == textprops["rotation"]
4686+
assert tx.get_rotation_mode() == textprops["rotation_mode"]
4687+
assert tx.get_size() == textprops["size"]
4688+
assert tx.get_color() == textprops["color"]
4689+
4690+
46694691
@image_comparison(baseline_images=['set_get_ticklabels'], extensions=['png'])
46704692
def test_set_get_ticklabels():
46714693
# test issue 2246

0 commit comments

Comments
 (0)