Skip to content

plt.subplot eats my subplots #11435

Closed

Description

Bug report

Bug summary

plt.subplot eats my subplots. But it doesn't completely digest them, since they are still there, just not shown.

Creating a subplot grid with plt.subplots and in addition adding a plt.subplot removes those subplots from the grid, which are under the newly created subplot.
Creating the additional subplot via fig.add_subplot does not remove them.

Code for reproduction

import matplotlib.pyplot as plt
fig, ax = plt.subplots(2,3,
                       subplot_kw={"label" : "A"}, 
                       gridspec_kw={'width_ratios':[1,1,3]})
ax[0,2].plot([1,2,3])

axi = plt.subplot(133, label="B")
axi.plot([7,6,5], color="red")
axi.axis("off")

plt.show()

Actual outcome

image

Expected outcome

The expected outcome would be the same as with fig.add_subplot:

axi = fig.add_subplot(133, label="B")
axi.plot([7,6,5], color="red")
axi.axis("off")

image

Matplotlib version

  • Operating system: Win 8.1
  • Matplotlib version: master
  • Matplotlib backend: Qt5Agg
  • Python version: 3.6

Activity

  1. fredrik-1 commented on Jun 13, 2018

    @fredrik-1
    Contributor

    I am currently looking at and editing those docstrings and that behavior is correct according to the docstrings and code. plt.subplot delete overlapping subplots and fig.add_subplot doesn't.

    I don't know why it is a difference in behavior.

  2. ImportanceOfBeingErnest commented on Jun 13, 2018

    @ImportanceOfBeingErnest
    MemberAuthor

    So you think this is desired? That feels a lot as if suddenly plt.title would create a title below the axes while ax.set_title creates it above or so.

  3. fredrik-1 commented on Jun 13, 2018

    @fredrik-1
    Contributor

    I don't understand why the feature exist but it is well documented https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.subplot.html#matplotlib.pyplot.subplot

  4. ImportanceOfBeingErnest commented on Jun 13, 2018

    @ImportanceOfBeingErnest
    MemberAuthor

    I see. My bad. I guess this can be closed, although I think this pretty annoying and should probably be changed at some point.

  5. jklymak commented on Jun 13, 2018

    @jklymak
    Member

    Matlab does this...

  6. anntzer commented on Jun 13, 2018

    @anntzer
    Contributor

    We can't blame everything on MATLAB, see #7377 (comment) and surrounding discussion (I haven't tried for subplot though).

  7. jklymak commented on Jun 13, 2018

    @jklymak
    Member

    Again, I wouldn't use plt.subplots and plt.subplot in the same figure and expect anything sensible to happen.

  8. added this to the v3.6.0 milestone on Mar 29, 2022
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions