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

Various examples updates. #10326

Merged
merged 1 commit into from Jan 27, 2018

Conversation

Projects
None yet
4 participants
@anntzer
Copy link
Contributor

commented Jan 26, 2018

  • don't import out of pyplot or numpy, import as plt/np.
  • move some examples to use subplots() instead of add_subplot.
  • set random seed for some examples.
  • fix some docstrings.

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

@anntzer anntzer added this to the v2.2 milestone Jan 26, 2018

@anntzer anntzer force-pushed the anntzer:examples branch from bf514e5 to 1e1429a Jan 26, 2018


fig = plt.figure(1, figsize=(6, 3))
fig, (ax1, ax2) = plt.subplots(1, 2)
fig.subplots_adjust(wspace=0.5)

This comment has been minimized.

Copy link
@timhoffm

timhoffm Jan 26, 2018

Member

Could be added to subplots via gridspec_kw.

This comment has been minimized.

Copy link
@anntzer

anntzer Jan 26, 2018

Author Contributor

Not convinced it's an improvement in legibility...

import matplotlib.pyplot as plt
from numpy import nonzero
from numpy.random import rand
from matplotlib import colors as mcolors, path, pyplot as plt

This comment has been minimized.

Copy link
@timhoffm

timhoffm Jan 26, 2018

Member

Not sure if mixed import and import as are easy to read.

This comment has been minimized.

Copy link
@anntzer

anntzer Jan 26, 2018

Author Contributor

disagree, but still split it out

"""
from matplotlib.pyplot import figure, show

from matplotlib import pyplot as plt

This comment has been minimized.

Copy link
@timhoffm

timhoffm Jan 26, 2018

Member

import matplotlib.pyplot as plt (also in various other locations, please search/replace)

This comment has been minimized.

Copy link
@anntzer

anntzer Jan 26, 2018

Author Contributor

fixed

# plot specifying units
ax2.plot(x, y, 'o', xunits=2.0)
ax2.set_title("xunits = 2.0")
plt.setp(ax2.get_xticklabels(), rotation=30, ha='right')

This comment has been minimized.

Copy link
@timhoffm

timhoffm Jan 26, 2018

Member

Broadcasting explicitly to a list of tick labels feels a bit clumsy. Is there maybe a method to set this for all tick labels, e.g. tick_params or similar?

This comment has been minimized.

Copy link
@anntzer

anntzer Jan 26, 2018

Author Contributor

tick_params can set labelrotation, but not horizontalalignment (and I don't think it's worth changing that, IMO setp actually does this job perfectly well...).

label.set_ha('right')
ax1.plot(x, y) # uses default units
ax1.set_title('default units')
plt.setp(ax1.get_xticklabels(), rotation=30, ha='right')

This comment has been minimized.

Copy link
@timhoffm

timhoffm Jan 26, 2018

Member

see above

This comment has been minimized.

Copy link
@anntzer

anntzer Jan 26, 2018

Author Contributor

ditto

t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)
t = np.arange(0.0, 3.0, 0.01)
s = np.sin(2*np.pi*t)

This comment has been minimized.

Copy link
@timhoffm

timhoffm Jan 26, 2018

Member

Do we have a convention, if this should include spaces around the operators? PEP8 would want them. Throughout the examples both variants are used.

This comment has been minimized.

Copy link
@anntzer

anntzer Jan 26, 2018

Author Contributor

See discussion at #7562 (comment) which I now agree with: I still believe spaces are in general good, but in some cases no spaces read better.
See also https://www.python.org/dev/peps/pep-0008/#other-recommendations ("use your own judgment", hehe).

@jklymak
Copy link
Contributor

left a comment

These changes are all fine +/- @timhoffm suggestions. Probably could make more, but overall the movement away from the pyplot interface is helpful.

Various examples updates.
- don't import out of pyplot or numpy, import as plt/np.
- move some examples to use subplots() instead of add_subplot.
- set random seed for some examples.
- fix some docstrings.

@anntzer anntzer force-pushed the anntzer:examples branch from 1e1429a to 09716fd Jan 26, 2018

@jklymak jklymak merged commit 358e087 into matplotlib:master Jan 27, 2018

8 checks passed

ci/circleci: docs-python27 Your tests passed on CircleCI!
Details
ci/circleci: docs-python35 Your tests passed on CircleCI!
Details
codecov/patch 100% of diff hit (target 50%)
Details
codecov/project/library 63.77% (target 50%)
Details
codecov/project/tests 98.83% (+0.47%) compared to f77243b
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
lgtm analysis: Python No alert changes
Details

@anntzer anntzer deleted the anntzer:examples branch Jan 27, 2018

@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.