Skip to content
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

DOC: Update some plotting code to current Matplotlib idioms #18652

Merged
merged 1 commit into from
Mar 21, 2021

Conversation

timhoffm
Copy link
Contributor

  • 3D Axes are created via add_subplot(projection='3d')
  • There is now a stairs() function that's specifically designed for
    showing histogram curves
  • Labels should be passed as keyword arguments to the plot functions
    instead of to legend(), which reduces the risk of mixing them up.

@rgommers
Copy link
Member

This looks great, thanks @timhoffm. One issue, the build is failing with:

AttributeError: module 'matplotlib.pyplot' has no attribute 'stairs'

How recently was stairs introduced? We can consider upgrading the minimum matplotlib version needed to build the docs. For that, stairs has to be in a release that's >=1 year old I'd say. Otherwise it's better to revert that change.

@charris
Copy link
Member

charris commented Mar 20, 2021

stairs was new in v3.4.0, might could be done with steps if v3.4.0 is too new.

@timhoffm
Copy link
Contributor Author

timhoffm commented Mar 21, 2021

I've reverted the use of stairs. Other ways to plot histograms from binned data are cumbersome/unituitive. That would be either using bars

>>> centers = (bins[1:] + bins[:-1]) / 2
>>> widths bins[1:] - bins[:-1]
>>> plt.bar(centers, n, width=widths)

or step (with the problem that steps expects equal-length inputs):

>>> plt.step(bins, np.insert(n, 0, [0]))

That's exactly why we've introduced stairs. I don't want to advertise any of the workarounds. So, I'm going back to the original plot. I've added a note that plt.stairs can be used for Matplotlib 3.4+. This way people can still learn the new function and it's more likely that somebody will remove plot from the docs some time in the future.

- 3D Axes are created via add_subplot(projection='3d')
- There is now a `stairs()` function that's specifically designed for
  showing histogram curves
- Labels should be passed as keyword arguments to the plot functions
  instead of to `legend()`, which reduces the risk of mixing them up.
- ensure equal axis scaling in the meshgrid example
Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

LGTM now, thanks @timhoffm

@rgommers rgommers merged commit 172251d into numpy:main Mar 21, 2021
@rgommers rgommers added this to the 1.21.0 release milestone Mar 21, 2021
@timhoffm timhoffm deleted the doc-plot branch March 21, 2021 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants