Skip to content

Commit a4048ae

Browse files
committed
Improved interaction of center and frame arguments
1 parent 8853d53 commit a4048ae

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,8 +2521,11 @@ def pie(self, x, explode=None, labels=None, colors=None,
25212521

25222522
if not frame:
25232523
self.set_frame_on(False)
2524-
self.set_xlim((-1.25, 1.25))
2525-
self.set_ylim((-1.25, 1.25))
2524+
2525+
self.set_xlim((-1.25 + center[0],
2526+
1.25 + center[0]))
2527+
self.set_ylim((-1.25 + center[1],
2528+
1.25 + center[1]))
25262529
self.set_xticks([])
25272530
self.set_yticks([])
25282531

lib/matplotlib/tests/test_axes.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,6 +3314,25 @@ def test_pie_linewidth_0():
33143314
plt.axis('equal')
33153315

33163316

3317+
@image_comparison(baseline_images=['pie_center_radius'], extensions=['png'])
3318+
def test_pie_center_radius():
3319+
# The slices will be ordered and plotted counter-clockwise.
3320+
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
3321+
sizes = [15, 30, 45, 10]
3322+
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
3323+
explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')
3324+
3325+
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
3326+
autopct='%1.1f%%', shadow=True, startangle=90,
3327+
wedgeprops={'linewidth': 0}, center=(1,2), radius=1.5)
3328+
3329+
plt.annotate("Center point", xy=(1,2), xytext=(1,1.5),
3330+
arrowprops=dict(arrowstyle="->",
3331+
connectionstyle="arc3"))
3332+
# Set aspect ratio to be equal so that pie is drawn as a circle.
3333+
plt.axis('equal')
3334+
3335+
33173336
@image_comparison(baseline_images=['pie_linewidth_2'], extensions=['png'])
33183337
def test_pie_linewidth_2():
33193338
# The slices will be ordered and plotted counter-clockwise.

0 commit comments

Comments
 (0)