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

Conversation

jerrylui803
Copy link
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

@@ -2670,8 +2670,9 @@ def pie(self, x, explode=None, labels=None, colors=None,
Notes
-----
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
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
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
Member

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

(Keeping things linked helps a lot!)

@@ -2672,6 +2672,9 @@ 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".
Copy link
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
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.

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
Member

Choose a reason for hiding this comment

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

extra z



@image_comparison(baseline_images=['pie_default'], extensions=['png'])
def test_pie_default_2():
Copy link
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.

Copy link
Contributor Author

@jerrylui803 jerrylui803 Mar 29, 2018

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
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
Copy link
Member

jklymak commented Mar 29, 2018

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.

@jerrylui803
Copy link
Contributor Author

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

@jklymak
Copy link
Member

jklymak commented Mar 29, 2018

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
Member

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

Hopefully we will hear from you again!

@tacaswell
Copy link
Member

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

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