-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Proposal: add_subfigs.... #17375
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
Thanks for thinking this further. Maybe it's just the terminology, but basing everything on a Figure inheritance hirarchy seems be too restrictive or impose undesired side-effects (e.g. if SubFigure inherits from Figure, can it have it's own dpi ?!?). I think of the layouting as a hirarchy of containers. Each container can contain further containers and artists. The container can decide how to distribute it's space among the contained elements. There is no explicit "sub"-anything, because the structure is recursive: The figure has a top-level container that spans the whole figure. In the simplest case, that could contain two Axes, but it could alternatively also contain more containers, that contain containers, ... , that contain an Axes, or a legend or .... I would design these containers around new classes, not inheriting from figure, subplot gridspec, etc. And only investigate afterwards how subplots and gridspecs can be mapped into this concept. Starting from scratch gives the freedom to come up with a clean an generic concept. OTOH I'm convinced if that is made flexible it can mimic subplots and gridspecs. |
So there are very few things that a
Thats exactly what this does. The sub-figures can have their own sub figures. If we want to call it something else, thats fine.
One of my goals is for this to be back-compatible with the existing API. If we were to start over we might do things differently. To be back compatible, the highest level "container" is the If we want to break back compatibility, that would be fine, but I don't see how or when that would be accepted into Matplotlib, and I forsee another Alternatively, we could tear out the guts of all the layout logic in |
Then, the inheritance hirachy is not
That's approximately the direction I'm thinking of. It provides a more clean separation beween layouting and plot elements such as figure and subplots. In the long run, I consider this to be more flexible and in particular also simpler to maintain than mangling the layout with (sub)figures. I would use composition and rather than inheritance for adding the layout capability. I don't have the time right now to dig into this, but would in principle be willing to work on a prototype for the concept. |
So right now I have |
I'm with with @timhoffm , calling this Which is a long way of saying, I am 👍 💯 on the concept. I think that a nice "middle" container is something we are missing, however I don't think we can use the word "Figure" in it's name (which is independent of implementation details). But, as we are painfully aware, getting the names wrong can cause a lot of issues later so should put in the effort to get this name right! Proposed names:
Words that I think of off-limits:
|
I'm fine calling it |
I guess the other thing that maybe should be clear is that I suppose its possible we could go the route of making a different transform (i.e. |
In #14421 there was some concern that
gridspec
was being overloaded and that something else should be doing that layout.I've mocked the following up, and it works quite well so far. Getting past mockup will be a fair bit of work, so wanted some comment.
For sub-grids, currently we would do:
Which is fine, for what it is. But imagine you want to have a colorbar that only pertains to
gs[0, 0]
or a legend just for that gridspec, or a suptitle. Currently we would have to add all that togridspec
. But as @timhoffm pointed out, gridspec is not really equipped for this sort of thing.Here instead I propose we create a new base class for
Figure
, sayFigureBase
and makeFigure
a subclass of that, andSubFigure
a subclass of that.FigureBase
contains all the layout-specific functions ofFigure
and all the figure-level artists (figure legends, figure colorbars, suptitle, future supx/ylabel, etc).FigureBase
then gets a new methodsubfigures
andadd_subfigure
, which give a virtual figure within the current figure.Now, instead of the above, we write:
You can also do
add_subfigure
using subplotspecsThe subfigs should be API-wise the same as a normal figure. And a subfig can then create subfigs. The subfigs keep track of their parent fig, and the parent keeps track of its subfigs, so traversing the tree is straight forward.
I think this is cleaner than overloading gridspec. Its semi-major surgery on Figure, but I've already implemented the above without too much pain. The layout is all achieved relatively painlessly by having a second transform with the parent so that if
x0
,y0
etc are in the parent's co-ordinates the subfigure has atransFigure
given by:Anyway, wanted to throw this out there for comment or thoughts. This seems a potentially cleaner way to arrange hierarchies of subplots.
The text was updated successfully, but these errors were encountered: