-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Some subplot axes not displaying when using both gridspec_kw/width_ratios and subplot2grid #11434
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
Comments
The problem is that the |
One could of course add the gridspec in use to the returned values from
|
Just to summarize here for others: The wish here is to not needing to use a This reminds me of @jklymak saying
I guess the time has come, the first request for such function is there. ;-) |
Right, best not to mix the You can do import matplotlib.pyplot as plt
fig, axs = plt.subplots(2,3,sharex=True, sharey=True, gridspec_kw={'width_ratios':[1,1,0.7]})
gs = axs[0, 0].get_subplotspec().get_gridspec()
ax = fig.add_subplot(gs[:, -1])
axs[0, -1].remove()
axs[1, -1].remove()
plt.show() A bit clunky, but works... |
I think it would be nice to have a clean way to do this instead of a workaround. Building off the first comment from @ImportanceOfBeingErnest, it could be something like:
where |
https://matplotlib.org/tutorials/intermediate/gridspec.html#sphx-glr-tutorials-intermediate-gridspec-py is the clean way to do this right now. If someone wants to try and add a 'gridspec' argument to |
In that tutorial,
I would offer to look into the addition of gridspec-type argument to |
I'm trying to think of the best API for this.
|
I love the idea of implementing Say we have Does I bring this up thinking about multiple calls to Regarding the disadvantage/ambiguity, I think a covered axis that is not in the list should not be clobbered. When the plot shows up, it will likely be easier for the user should to figure out why axes are overlapping than to figure out why axes suddenly disappeared. As a side benefit, leaving non-listed axes as-is gives one the opportunity to make neat (if not confusing) axis-within-axis plots using the |
To me it looks a lot like In general my point of view is that axes should never get removed. Given that there apperently is a good way of obtaining the gridspec of an axes via |
Right, well if axes are never removed (unless the user removes them), then there is little point in OTOH, the use cases aren't that hard. Any included axes are removed; the extent of the new axes is the same as the extent of the listed axes; the new axes would be a new axes with no sharing etc except maybe by kwarg. i.e it'd just be |
See #11438 |
Closing because #11438 was merged. OTOH we can reopen if folks think the conveneoence method isn’t enough. |
Bug report
Bug summary
When using a combination of
plt.subplots
withgridspec_kw/width_ratios
along withplt.subplot2grid
, some of the axes disappear when one of the width ratios is (in this case) below 0.73.Code for reproduction
Actual outcome
Note that the axes only disappear with the call to
subplot2grid
. If I remove that line, all axes appear.Expected outcome
If

width_ratios
is instead[1,1,0.8]
, all of the axes appear.I can achieve the desired width ratios if I use
GridSpec
directly instead of using the wrappers, but it would be nice if the wrappers didn't fail based on thewidth_ratios
parameter.Matplotlib version
mabplotlib and python installed via conda.
The text was updated successfully, but these errors were encountered: