Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

use plt.subplots() in examples as much as possible#1458

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
ivanov wants to merge2 commits intomatplotlib:masterfromivanov:use-subplots

Conversation

ivanov
Copy link
Member

At the recent LBL Software Carpentry Workshop, it was pointed out that there's
an inconsistency within our documentation for how to create new figures with
subplots.

Indeed, most examples were using the old way, something like:

fig = plt.figure()ax = plt.subplot(111) # or plt.add_subplot(111)

This patch changes a whole bunch of instances like the above to:

fig, ax = plt.subplots()

We should strive to have a minimal amount of constants in our code,
especially unusual ones like111, which only make sense to Matlab
refugees. This PR ends up removing ~150 lines with subplot(X), where X is some constant, as well as a comparable number of plt.figure() calls.

I have left unchanged examples which were using axes keywords passed to
subplot() and add_subplot(), since those end up transforming things like:

figure()subplot(111, axisbg='w')

to

plt.subplots(subplot_kw=dict(axisbg='w'))

which isn't necessarily better.

I also did not touch most of the user_interfaces examples, since those did not
involve using plt, but instead explicitly imported Figure, and used the OO
approach on Figure instances.

Also updated instaces where the old "import pylab as p" convention was used to
use our standard "import matplotlib.pyplot as plt"

I have also updated some, but not all uses of subplot(121) etc, but I'm a bit
exhausted after doing all of these.

At the recent LBL Software Carpentry Workshop, it was pointed out that there'san inconsistency within our documentation for how to create new figures withsubplots.Indeed, most examples were using the old way, something like:    fig = plt.figure()    ax = plt.subplot(111) # or plt.add_subplot(111)This patch changes a whole bunch of instances like the above to:    fig, ax = plt.subplots()We should strive to have a minimal amount of constants in our code,especially unusual ones like `111`, which only make sense to Matlabrefugees.I have left unchanged examples which were using axes keywords passed tosubplot() and add_subplot(), since those end up transforming things like:    figure()    subplot(111, axisbg='w')to    plt.subplots(subplot_kw=dict(axisbg='w'))which isn't necessarily better.I also did not touch most of the user_interfaces examples, since those did notinvolve using plt, but instead explicitly imported Figure, and used the OOapproach on Figure instances.Also updated instaces where the old "import pylab as p" convention was used touse our standard "import matplotlib.pyplot as plt"I have also updated some, but not all uses of subplot(121) etc, but I'm a bitexhausted after doing all of these.
@dmcdougall
Copy link
Member

Good lord, 132 files changed! That said, I think most of the changes you have made make the code better and clearer. The examples are probably the thing our users look at most. Certainly when I don't know how to do something and I see a picture in the gallery I look at the example source code for clues. Have example source code that is as clear as possible is only going to make our users happier.

@ivanov Thank you very much for your heroic effort.

@pelson
Copy link
Member

Repeated in#1462 (targeted againstv1.2.x). Please make all reviews in that PR so that we can all sing off the same hymn sheet. I will close this PR temporarily until we have a review complete. (hope that's ok@ivanov )

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@ivanov@dmcdougall@pelson

[8]ページ先頭

©2009-2025 Movatter.jp