Skip to content

Commit a10b90c

Browse files
jerrylui803tacaswell
authored andcommitted
Changed pie charts default shape to circle and added tests (#10914)
API: set aspect in Axes.pie to be 'equal' * Changed pie charts default shape to circle (instead of oval), and added tests * Updated comments for default circular pie chart * fix pep8 * removed unneccessary test case and updated docstring * added what's new entry and edited docstring for pie * fix pep8 * fixed typo
1 parent 0b0a6a0 commit a10b90c

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Pie charts are now circular by default
2+
--------------------------------------
3+
We acknowledge that the majority of people do not like egg-shaped pies.
4+
Therefore, an axes to which a pie chart is plotted will be set to have
5+
equal aspect ratio by default. This ensures that the pie appears circular
6+
independent on the axes size or units. To revert to the previous behaviour
7+
you may set the axes' aspect to automatic, ax.set_aspect("auto") or
8+
plt.axis("auto").

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,7 +2624,10 @@ def pie(self, x, explode=None, labels=None, colors=None,
26242624
-----
26252625
The pie chart will probably look best if the figure and axes are
26262626
square, or the Axes aspect is equal.
2627+
This method sets the aspect ratio of the axis to "equal".
2628+
The axes aspect ratio can be controlled with `Axes.set_aspect`.
26272629
"""
2630+
self.set_aspect('equal')
26282631
x = np.array(x, np.float32)
26292632

26302633
sx = x.sum()

lib/matplotlib/tests/test_axes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4540,6 +4540,18 @@ def test_text_labelsize():
45404540
ax.tick_params(direction='out')
45414541

45424542

4543+
@image_comparison(baseline_images=['pie_default'], extensions=['png'])
4544+
def test_pie_default():
4545+
# The slices will be ordered and plotted counter-clockwise.
4546+
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
4547+
sizes = [15, 30, 45, 10]
4548+
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
4549+
explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')
4550+
fig1, ax1 = plt.subplots(figsize=(8, 6))
4551+
pie1 = ax1.pie(sizes, explode=explode, labels=labels, colors=colors,
4552+
autopct='%1.1f%%', shadow=True, startangle=90)
4553+
4554+
45434555
@image_comparison(baseline_images=['pie_linewidth_0', 'pie_linewidth_0',
45444556
'pie_linewidth_0'],
45454557
extensions=['png'])

0 commit comments

Comments
 (0)