Skip to content

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

Merged
tacaswell merged 7 commits into
matplotlib:masterfrom
jerryluicy:pie_chart
Mar 31, 2018
Merged

tacaswell merged 7 commits into
matplotlib:masterfrom
jerryluicy:pie_chart

Conversation

@jerryluicy

Copy link
Copy Markdown
Contributor

github.com//issues/10789

As seen in the issue link above, a simple way to generate a pie graph is using plt.pie, and the second method to generate a pie graph is by using plt.subplots. Both of these approaches creates the pie graph through _axes.py by using an Axes instance which calls its pie method; the additional line to add calls the set_aspect function, which sets the aspect of the axis scaling, with ‘equals’ as parameters and this results in a default circular pie graph with an equal aspect ratio as wanted.
Some test cases are also added.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

Comment thread lib/matplotlib/axes/_axes.py Outdated
-----
The pie chart will probably look best if the figure and axes are
square, or the Axes aspect is equal.
square, or the Axes aspect is equal, this is the default setting.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not the default setting, its the only setting. Suggest:

This method sets the aspect ratio fo the axis to ``equal``.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to say that is the default setting for pie, but I think what you said is more clear, thanks

@ImportanceOfBeingErnest

Copy link
Copy Markdown
Member

This is a rework of #10887 and should fix #10789.

(Keeping things linked helps a lot!)

Comment thread lib/matplotlib/axes/_axes.py Outdated
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".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be a comment but part of the docstring. Please rework the note in the doctring to reflect the new behavior.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, yeah, this should be the Note part of the docstring, not a comment.

Comment thread lib/matplotlib/tests/test_axes.py Outdated
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')z

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra z

Comment thread lib/matplotlib/tests/test_axes.py Outdated


@image_comparison(baseline_images=['pie_default'], extensions=['png'])
def test_pie_default_2():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the two test? Is it for ax.pie vs pyplot.pie? I'm not sure if we need both. pyplot.pie is just a very thin wrapper around Axes.pie. Maybe someone with more experience on matplotlib tests can comment on this.

If both should stay, please name them semantically, e.g. ..._axes, ..._pyplot instead of just numbering them.

@jerryluicy jerryluicy Mar 29, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it's axes.pie vs pyplot.pie, I added 2 tests because sometimes it might pass the pyplot.pie test and fail the axes.pie test (this is the case if you add axis("image") to pyplot.pie) , but I am not sure if its always the case that if axes.pie passes then pyplot.pie must also pass.
edit: Thanks, looks like only one is needed

@ImportanceOfBeingErnest

Copy link
Copy Markdown
Member

Comments in #10789 mention a what's new entry. Is this necessary or is it a too small change? Also, should the docstring state how to revert to the old behaviour?

@jklymak

jklymak commented Mar 29, 2018

Copy link
Copy Markdown
Member

Yes an entry in doc/users/next-whats-new/ is called for.

It couldn't hurt to say:

The axes aspect ratio can be controlled with `.Axes.set_aspect`.  

Thanks @ImportanceOfBeingErnest for noting that.

@jerryluicy

Copy link
Copy Markdown
Contributor Author

add in both doc/users/next-whats-new/ and also the docstring for pie ?

@jklymak

jklymak commented Mar 29, 2018

Copy link
Copy Markdown
Member

See the other whats-new entries for examples of what should go in there. The not about how to set aspect ratio should be in the docstring

@dstansby dstansby added this to the v3.0 milestone Mar 30, 2018
@tacaswell
tacaswell merged commit a10b90c into matplotlib:master Mar 31, 2018
@tacaswell

Copy link
Copy Markdown
Member

Thanks @jerrylui803 and congratulations on your first Matplotlib contribution 🎉 !

Hopefully we will hear from you again!

@tacaswell

Copy link
Copy Markdown
Member

housekeeping: I squash-merged this to reduce code churn.

@timhoffm timhoffm mentioned this pull request Apr 3, 2018
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants