-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: Allow axes to have child axes. #11005
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
To avoid confusion with the existing
The question is then in how far this would be compatible with all the inset_locator module's functionality like bbox connectors, |
inset axis is well on its way in #11026 Lets hash out an API for def conversionx(x):
return np.log10(x) + 31.5
extrax = ax.extra_spine_x(location='top', convert=conversionx)
# or
extrax = ax.extra_spine_x(location=1.0, convert=conversionx)
# or
ax.plot(range(10))
extrax = ax.extra_spine_x(location=4.0, convert=conversionx, transform=ax.transData)
# this last one would put the new x-spine at 4.0 in *data* space. One could also imagine an ax.plot(range(10))
extrax = ax.extra_spine_x(location=4.0, convert=conversionx)
# this last one would put the new x-spine at 4.0 in *data* space. You could also imagine having an extent and offset keywords so the spine doesn't span the whole axis, but that would also need a way to map the xlims (which presumably would not be the full extent of the parent x axis. Seems complicated, and rarely used, and a need that could be met w/ Issues
|
In general 👍
|
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(range(20))
xl = ax.get_xlim()
secondax = ax.twiny()
secondax.set_xlim(xl[0]*10+30., xl[1]*10+30)
secondax.tick_params('y')
ax.set_xlim([0, 10])
plt.show() doesn't return the correct x-axis because there is nothing tying the x-axis-es together (its the y-axis that is shared). Thats as it should be for a twinned axis; the two data types in the two axes should definitely be allowed to have independent x-axes.
|
So in total I would say, similar to what exists now one would do
to place the spine at
|
I was conceiving of the extra_spine as not having a cross-spine dimension and having to track all the cross-spine info from the parent axes. That makes life a lot easier and we avoid all the issues with aspect ratios and twinning. If we were to go that route, then Probably we could make it work the |
I was under the impression that the extra_axes would create a normal boxed axes, which just has 3 spines tuned off and whose scaling, limits, and position is tied to the parent. In that case, calling |
Yes, but that wasn't the plan given the PITA that fully-twinned axes are.... A specially-placed extra spine gets special treatment because its being specially placed. I'm not 100% against the alternative of having a fully formed axes, but it just seems prone to inconsistencies.. i.e. if you set the aspect ratio on the main axes, and the child axes has a conversion on the x-axis, then it cannot share the aspect ratio of the parent, but rather needs to set its position based on the aspect-applied position of the parent. It can be done, but it all gets pretty complex, just for the ability to manually place the spine, which I was planning to allow anyways... |
Ok, I think I finally understand.. this is really just about getting a scale in some other units attached to an axes. So at the end you have
... each of which is somehow incomplete. |
I don't think "completeness" is necessarily desirable. Thats how you end up with the El Camino (https://en.wikipedia.org/wiki/Chevrolet_El_Camino), something which doesn't do anything well or clearly. In this case, I don't think its necessarily good for |
I think this functionality is all in now.... |
Suggestion
This would subsume #10976: see #10961 #10960 for secondary axes requests.
See #8952 for the poor state of documentation and confusing behaviour of
axes_grid1.inset_axes
. #10986, #10756There are a few instances where it would make sense for an axes to have an axes as a child artist:
matplotlib/lib/mpl_toolkits/axes_grid1/inset_locator.py
Lines 389 to 390 in adaa8e5
I'd propose we create an API for these. I would expect the legend API would be fine for inset axes, and would closely follow the one already in axes_grid1. An example would be:
Secondary axes would be basically an
inset_axes
, except with the appropriate spines turned off:Implementation
I would like to have these be children of the parent axes simply for the reason that they are decorators, and should be included in the list of artists a) at draw time, and b) when the bbox for the parent axes is calculated for tools like constrained_layout and tight_layout. Also having them as children makes it possible to change the limits if the parent limits change, and avoids the messiness of twin axes, which have a peer-to-peer relationship.
The text was updated successfully, but these errors were encountered: