Skip to content

Changed pie charts default shape to circle and added tests #10914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/users/next_whats_new/pie_chart_default.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Pie charts are now circular by default
--------------------------------------
We acknowledge that the majority of people do not like egg-shaped pies.
Therefore, an axes to which a pie chart is plotted will be set to have
equal aspect ratio by default. This ensures that the pie appears circular
independent on the axes size or units. To revert to the previous behaviour
you may set the axes' aspect to automatic, ax.set_aspect("auto") or
plt.axis("auto").
3 changes: 3 additions & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2671,7 +2671,10 @@ def pie(self, x, explode=None, labels=None, colors=None,
-----
The pie chart will probably look best if the figure and axes are
square, or the Axes aspect is equal.
This method sets the aspect ratio of the axis to "equal".
The axes aspect ratio can be controlled with `Axes.set_aspect`.
"""
self.set_aspect('equal')
x = np.array(x, np.float32)

sx = x.sum()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4540,6 +4540,18 @@ def test_text_labelsize():
ax.tick_params(direction='out')


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


@image_comparison(baseline_images=['pie_linewidth_0', 'pie_linewidth_0',
'pie_linewidth_0'],
extensions=['png'])
Expand Down