Skip to content

make subplots smarter with regards to subplot_kw and figure_kw #1460

Closed

Description

@ivanov

While working on #1458, it occurred to me that it might not be a bad idea to process the keyword arguments given to plt.subplots and pass them along in the appropriate direction. As I alluded to in #1458, currently, to replace lines like:

fig = plt.figure(figsize=(10,20))
ax = plt.subplot(111, axisbg='w')

you have to do an awkward thing to subplot's keyword arguments, since, subplot*s* passes its keyword arguments to plt.figure.

fig, ax = plt.subplots(figsize=(10,20), subplot_kw=dict(axisbg='w'))

but, at least as I was going through our examples, all of the subplot keyword arguments were pretty unambiguously named, and could not be interpreted as figure keyword arguments. So there's no reason why we shouldn't make the next line work the same as the two examples above:

fig, ax = plt.subplots(figsize=(10,20), axisbg='w')

in our docs, plt.axes takes these kwargs:

axisbg    color          the axes background color
frameon   [True|False]   display the frame?
sharex    otherax        current axes shares xaxis attribute with otherax
sharey    otherax        current axes shares yaxis attribute with otherax
polar     [True|False]   use a polar axes?

and plt.subplot says it deals with axisbg, polar, and projection

Activity

  1. added a commit that references this issue on Sep 16, 2013
  2. added this to the milestone on Aug 17, 2014
  3. modified the milestones: , on Oct 3, 2017
  4. added
    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
    and removed on Jun 1, 2019
  5. JacobChamberlain commented on Mar 3, 2020

    @JacobChamberlain

    Is anyone else currently working on this? If not I'll give it a try.

  6. jklymak commented on Mar 3, 2020

    @jklymak
    Member

    @JacobChamberlain sure, but be prepared for some discussion as to whether this is a good idea. I tend to think it is a good idea, because those kwarg dictionaries are pretty ugly and hard for users to grok, but there may be subtleties I'm not aware of.

  7. JacobChamberlain commented on Mar 3, 2020

    @JacobChamberlain

    @jklymak We suspect we may run into some issue. I'll let you know what issues we find, but those dictionaries are pretty ugly so any clean up is an improvement in my book.

  8. ivanov commented on Apr 17, 2020

    @ivanov
    MemberAuthor

    At the time I created this issue (seven and a half years ago), subplots had "only" been around for two years (in matplotlib proper, anyway), thus somewhat new, and certainly underutilized, to the point where none of our examples were using it, which meant that many of our users were unaware of it. The proposal was to make it easier for folks to transition to using it, in particular since a lot of our examples used the pattern of

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

    which using subplots (then and in its current form) could become

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

    and was not necessarily better. Since subplot (singular) forwarded its keyword arguments to plt.axes, which back then were documented as axisbg, frameon, sharex, sharey, and polar, and given that sharex and sharey already were part of the subplots (plural) keywords (though now accepting boolean values), I thought it might be ergonomic to make those arguments pass directly from subplots' kwargs (or make them all into top level keyword arguments, even).

    Now that it's been another seven and half years later, it probably no longer makes sense to make the advertised keyword arguments of subplot (singular) available directly in subplots without relegating them to the subplot_kw keyword argument.

    Unless I'm misreading the conversation between @sabulikia, @QuLogic , and @tacaswell over in #16738, it seems like we should close this issue?

  9. anntzer commented on Apr 17, 2020

    @anntzer
    Contributor

    I agree this should be closed.

  10. modified the milestones: needs sorting, on Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    API: changesChanges to the public API, typically requiring deprecation.Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesNew feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions