Skip to content

plt.subplot eats my subplots #11435

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
ImportanceOfBeingErnest opened this issue Jun 13, 2018 · 7 comments · Fixed by #22418
Closed

plt.subplot eats my subplots #11435

ImportanceOfBeingErnest opened this issue Jun 13, 2018 · 7 comments · Fixed by #22418
Milestone

Comments

@ImportanceOfBeingErnest
Copy link
Member

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
@fredrik-1
Copy link
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.

@ImportanceOfBeingErnest
Copy link
Member Author

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.

@fredrik-1
Copy link
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

@ImportanceOfBeingErnest
Copy link
Member Author

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

@jklymak
Copy link
Member

jklymak commented Jun 13, 2018

Matlab does this...

@anntzer
Copy link
Contributor

anntzer commented Jun 13, 2018

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

@jklymak
Copy link
Member

jklymak commented Jun 13, 2018

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

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 a pull request may close this issue.

5 participants