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

Skip to content

ENH: add get_gridspec convenience method to subplots #11438

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 3 commits into from
Jul 7, 2018

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Jun 14, 2018

PR Summary

As per #11434 its a bit of a pain to get the gridspec after calling plt.subplots(). This change lets you do the following, where the only really change is that we don't have to do the more cumbersome gs = ax.get_suplotspec().get_gridspec(). Much more discoverable.

To do: Add to gridspec tutorial which I'll d if this is in general OK. I don't see the harm in adding this.

    import matplotlib.pyplot as plt

    fig, axs = plt.subplots(3, 2)
    gs = axs[0, -1].get_gridspec()

    # remove the last column
    for ax in axs[:,-1].flatten():
      ax.remove()

    # make a subplot in last column that spans rows.
    ax = fig.add_subplot(gs[:, -1])
    plt.show()

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)

Copy link
Member

@ImportanceOfBeingErnest ImportanceOfBeingErnest left a comment

Choose a reason for hiding this comment

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

This simplifies many cases where otherwise each axes would need to be created from a GridSpec individually.

There is indeed also no harm in introducing this as it only gives a shortcut to already present (but somehow hidden) methods.

Approved, but would like to see a proper documentation (possibly in a follow up PR), best within the gridspec tutorial.

@jklymak
Copy link
Member Author

jklymak commented Jun 15, 2018

Yes, will definitely include an example and gridspec tutorial edit.... Just wanted to make sure the proposed change had enough support before going nuts...

@jklymak
Copy link
Member Author

jklymak commented Jun 17, 2018

OK, this now has documentation (example + tutorial edit).

@jklymak jklymak force-pushed the enh-get-gridspec branch from c84db54 to 4983637 Compare June 17, 2018 16:30
-----------------------------------------

New method `.SubplotBase.get_gridspec` is added so that users can
easily get the gridspec that went into making as axes:
Copy link
Member

Choose a reason for hiding this comment

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

as -> an

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

modulo a typo in whats new

@jklymak
Copy link
Member Author

jklymak commented Jun 21, 2018

This needs a second review to merge, It’s a one-liner plus docs...

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

You're having three times almost the same example, onces in "What's new", once within the gridspec tutorial once as a separate example. Is this duplication reasonable?

==================================================

Sometimes we want to combine two subplots in an axes layout created with
`.figure.subplots`. We can get the `.gridspec.Gridspec` from the axes
Copy link
Member

Choose a reason for hiding this comment

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

Links do not resolve. Possibly use ~.Figure.subplots and ~.gridspec.GridSpec

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!. I'll fix the links.

The whats new is kind of ephemeral.

My understanding is that there are two types of people in the matplotlib community (that actually read the docs): those that read the examples, and those that read the tutorials. Indeed a lot of the examples are historically just sections from some tutorials. I don't think the duplication is egregious, but happy to remove any/all if that is what folks want.

@jklymak jklymak force-pushed the enh-get-gridspec branch from 101b34e to d2a1456 Compare June 24, 2018 21:04
@jklymak jklymak force-pushed the enh-get-gridspec branch from d2a1456 to 740ec16 Compare July 4, 2018 19:43
@jklymak jklymak closed this Jul 6, 2018
@jklymak jklymak reopened this Jul 6, 2018
@jklymak
Copy link
Member Author

jklymak commented Jul 6, 2018

Recycling for CI

@tacaswell
Copy link
Member

Merging on a combination of @ImportanceOfBeingErnest 's review and reading it a second time forgetting I had already approved this PR and went to approve it again.

@tacaswell tacaswell merged commit 21b102e into matplotlib:master Jul 7, 2018
@tacaswell
Copy link
Member

The failure was wx on osx

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