Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use sublots in examples #1598

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

Closed
wants to merge 5 commits into from
Closed

Use sublots in examples #1598

wants to merge 5 commits into from

Conversation

ivanov
Copy link
Member

@ivanov ivanov commented Dec 14, 2012

this is a rebase of #1462 against master, as discussed on that PR. I believe it is ready to merge

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 like `111`, which only make sense to Matlab
refugees.

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.
---------------------------
For the sake of brevity and clarity, most of the :ref:`examples
<examples-index>` now use the newer :func:`~matplotlib.pyplot.subplots`
, which creates a figure and one (or multiple) axes object(s) in one
Copy link
Member

Choose a reason for hiding this comment

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

comma shouldn't be line wrapped here

@mdboom
Copy link
Member

mdboom commented Dec 17, 2012

I haven't picked through this with a fine-toothed comb, but +1 in general.

We should try to get this merged before the MEP12 work gets underway -- this is a good start to the example/gallery cleanup that is planned.

@@ -24,13 +24,13 @@ class BlitQT(QObject):
def __init__(self):
QObject.__init__(self, None, "app")

self.ax = p.subplot(111)
self.ax = plt.axes()
Copy link
Member

Choose a reason for hiding this comment

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

fig isn't used anywhere? Is that why you didn't do the usual fig, ax = plt.subplots() here?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, that's right, using axes was suggested by @pelson here. Though now that this is back against master, I will just change this to the new plt.subplot()

@dmcdougall
Copy link
Member

I fine-toothed it. That took a fair bit of stamina, but I think I've provided some helpful feedback for @ivanov. Let me know if there's anything else I can do. Other than that I think this is good to go.

@mdboom Was there a consensus on whether this should also go into v1.2.x?

@ivanov
Copy link
Member Author

ivanov commented Dec 17, 2012

@dmcdougall I think the final word was that this should not go into v1.2.x, which is why I closed that PR. Thanks for your feedback, I'll just add a commit addressing this round of reviews shortly

@dmcdougall
Copy link
Member

Surely there is no way b34b6b7 caused that Python 3.2 Travis failure...

@ivanov
Copy link
Member Author

ivanov commented Dec 18, 2012

yeah, the false positive rate for Travis is pretty frustrating :\

@mdboom
Copy link
Member

mdboom commented Jan 16, 2013

Sorry this got dropped. I'm worried that it may be really difficult to merge with #1623 which moves around many of the examples. Maybe this could be rebased off of #1623 and merged in there. In any event, this will need some coordination between at least @ivanov, @tonysyu and myself.

@pelson
Copy link
Member

pelson commented Apr 18, 2013

Ouch. I agree with @mdboom on this one - this is very much desirable, but getting this into a position where it plays nicely with @tonysyu changes (and any other changes which have happened since this PR was created) could be a nightmare. I think smaller PRs are the way forward here.

@mdboom
Copy link
Member

mdboom commented May 21, 2013

Sometimes git really shines. It actually was able to do this rebase fairly smoothly and tracked the many moved files just fine. I'm put up a rebased version of this PR in #2043 so @ivanov's hard work doesn't go to waste. I can't guarantee it's complete (i.e. using subplots everywhere), but it's a definite improvement.

@efiring
Copy link
Member

efiring commented May 25, 2013

I'm closing this because it is replaced by #2043.

@efiring efiring closed this May 25, 2013
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.

5 participants