-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Adding subplots dynamically with constrained_layout #19730
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
Can you give us some more explanation of what doesn't work, preferably with some code? If you mean you keep tearing gridspecs down and adding new ones, and reassigning axes to the new one, that could indeed be problematic. OTOH, did you try this on matplotlib master? constrained_layout has had a rewrite that makes the layout properties less dependent on the axes and more so on the gridspec. But I wouldn't expect miracles - it is written assuming a known gridspec and isn't meant to be changed dynamically on the fly. |
BTW, users are always welcome to use the internal API, they just can't complain if it changes ;-) |
Thanks for the quick reply. I will try the master and report back. However, yes, I do change gridspecs a lot! Isn't there a simple way to "restart" the layout solver with a complete new gridspec? |
Yes - clear the figure. If I need to change the number of subplots I just restructure my script to do so and rerun it. I don't think that it is more efficient to move things around, rather than just start over. |
This is a little bit inconvenient. I can understand you do not support arbitrary changes of gridspec, but the complete gridspec of the figure and full reset of constrained layout would be nice. The approach you suggest works for generating static figures (for publications for instance). But adding a little bit of interaction like in my case where I just want to add another stacked axes, reformatting and reading all the existing lines and artists that are already there it is painful and inefficient. Unfortunately, I was not able to run directly the master branch, some unexpected error. I will keep trying... |
Again, it would be nice if you gave us a sequence of what you are doing, as runnable code, so we can see what the problem is. |
Thanks for the reproducible example. I didn't even know we had |
For an interactive interface where the user can add more plots, it seems impossible to use constrained_layout.
The whole adding a new axes is unnecesarily complex but it can be done. A new gridspec is set-up and the current axes are repositioned into their new "slots". This is working.
However the constrained_layout solver fails (error that height or width is 0).
Proposed Solution
It seems that some work has already been performed as part of setting a colorbar. It seems to me that with some effort it would be possible to extend that solution to be more generic.
Otherwise the whole layout boxes set-up could be exposed to the external API, such that the users can use it in a similar fashion.
(Ideally the matploplib API could make simpler adapating the gridspec after it has been created)
Additional context and prior art
None
The text was updated successfully, but these errors were encountered: