-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow passing figure handle to FacetGrid #7401
Comments
I think the usual workflow is to create the figure with gridspec and then update the created subplots and figure. Is there something that is not possible if done this way around? |
I have actually manage to make it work with minimal modification of the source xarray code: import xarray as xr
import matplotlib.pyplot as plt
import matplotlib as mpl
def _pass(*_,**__):
pass
mpl.figure.SubFigure.tight_layout = _pass
da = xr.tutorial.open_dataset("air_temperature")['air']
fig:plt.Figure = plt.figure(
constrained_layout=True,
figsize = (2*4,2*2)
)
(fig_top,fig_bot) = fig.subfigures(2,1)
(
da.groupby(da['time'].dt.season)
.mean()
.plot(col='season',fig=fig_top)
)
(
da.groupby(da['time'].dt.hour)
.mean()
.plot(col='hour', fig=fig_bot)
) |
Good point. Combining two f, axs = plt.subplots(2, 4)
da1.plot(col='season', ax=axs[0, :])
da2.plot(col='season', ax=axs[1, :]) |
Seems like a good addition to me. I'm not sure about passing Axes handles. IIRC FacetGrid does call a bunch of Figure methods, so there may be unintended consequences |
Is this still on the table? I think being able to pass a figure handle would be good for all the reasons mentioned above, but also it would allow us to use CC @jbusecke |
Is your feature request related to a problem?
Sometimes i need to combine xarray Facet grids with other ax plots. It would be amazing if I could pass a created figure to the plot function. Event better a subfigure so that the possibilities are infinite!
Describe the solution you'd like
for example:
Describe alternatives you've considered
an alternative is to manually to all plots in a created figure, but this becomes cumbersome.
I quickly checked the source code, and it does not seem very difficult to implement. mostly a modification to the
get_axis function so that it accepts an already created figure. I managed to quickly make it work in seaborn (see image below)
Additional context
No response
The text was updated successfully, but these errors were encountered: