-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add ability to pass different kwargs when adding different subplots simultaneously throughplt.subplots
#20392
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
We have a way to do this already, which is to make the gridspec and then add the axes individually. I'm not sure how constructing an array of dicts is a preferable interface. |
That's fair, though that gets tedious for complicated layouts -- helper functions in |
You cannot change an axes' projection trivially. However, you can get the subplotspec and make a new axes like: import matplotlib.pyplot as plt
fig = plt.figure()
axs = fig.subplot_mosaic([['A', 'B'], ['C', 'B']])
ss = axs['B'].get_subplotspec()
axs['B'].remove()
axs['B'] = fig.add_subplot(ss, projection='3d')
plt.show() |
Ah, this makes a lot of sense! That covers my particular use case, thanks :) Happy for the issue to be closed if you don't deem the original post to be an appropriate feature, but also open to more discussion! |
I guess I'm somewhat against trying to make the API for subplot_mosaic too complicated. Note we also have subfigures, which is another way of dealing with different projections in the same figure: https://matplotlib.org/stable/gallery/subplots_axes_and_figures/subfigures.html |
I'll close here, and we can continue discussion on discourse.matplotlib.org... https://discourse.matplotlib.org/t/modifying-an-axessubplot-to-be-3d-in-the-context-of-plt-subplot-mosaic/22158 |
Problem
I was just messing aroung with trying to see if I could use the (super nice!)
plt.subplot_mosaic
function with a mixture of 2d and 3d axes, but didn't get anywhere. Looking into it, it seems like it could be possible withsubplot_kw = {"projection": "3d"}
, but this is static across the different subplots (or more accurately, calls toplt.add_subplot
).Proposed Solution
From looking at the source code (specifically at these line in
gridspec.py
, since that's where I believe the function calls eventually end up) it seems like it may be possible to packagesubplot_kw
s in an object of size_nrows
x_ncols
, since that is the dimensions iterated over.matplotlib/lib/matplotlib/gridspec.py
Lines 299 to 308 in 9c530bc
The only part that's unclear to me from an implementation standpoint is whether this would necessitate a new kwarg itself, or perhaps one can use single dispatch or conditional logic to handle the case where
subplot_kw
is not dict-like.Happy to have a go if this is desired and/or the functionality exists already and I'm blindsighted to it :)
Additional context and prior art
Could be many scenarios where one would want to control each subplot! I think it would be super neat to be able to do all this from one call to
plt.subplots
:DThe text was updated successfully, but these errors were encountered: