-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
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 with subplot_kw = {"projection": "3d"}, but this is static across the different subplots (or more accurately, calls to plt.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 package subplot_kws 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
| # Create array to hold all axes. | |
| axarr = np.empty((self._nrows, self._ncols), dtype=object) | |
| for row in range(self._nrows): | |
| for col in range(self._ncols): | |
| shared_with = {"none": None, "all": axarr[0, 0], | |
| "row": axarr[row, 0], "col": axarr[0, col]} | |
| subplot_kw["sharex"] = shared_with[sharex] | |
| subplot_kw["sharey"] = shared_with[sharey] | |
| axarr[row, col] = figure.add_subplot( | |
| self[row, col], **subplot_kw) |
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 :D