diff --git a/doc/users/next_whats_new/pie_chart_default.rst b/doc/users/next_whats_new/pie_chart_default.rst new file mode 100644 index 000000000000..2b7c7b9c59cd --- /dev/null +++ b/doc/users/next_whats_new/pie_chart_default.rst @@ -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"). \ No newline at end of file diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index d476deb356fd..2af954208a3c 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -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() diff --git a/lib/matplotlib/tests/baseline_images/test_axes/pie_default.png b/lib/matplotlib/tests/baseline_images/test_axes/pie_default.png new file mode 100644 index 000000000000..1c0c6c2c0577 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/pie_default.png differ diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 479e55b37251..84dc5be19971 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -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'])