You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, secondary_xaxis is implemented by adding a child axes with a
physical height set to zero and y position set accordingly relative to
its parent axes (using the axes_locator mechanism).
This patch changes it so that the child axes' extents actually
*matches* the parent axes, and instead positioning the spines using
Spine.set_position. It also makes sure that the secondary axes patch is
invisible and that the bounds of the "orthogonal" axis (the one that is
not shown) matches the parent bounds.
By doing so, it becomes possible to plot data directly on the secondary
axis as well; e.g. the following now works:
```
from matplotlib import pyplot as plt
from matplotlib.axes import Axes
fig, ax0 = plt.subplots()
ax1 = ax0.secondary_xaxis(
"top", functions=(lambda x: x**3, lambda x: x**(1/3)))
Axes.plot(ax1, [.25, .5, .75], [.25, .5, .75], ".-")
plt.show()
```
(We have to use Axes.plot here instead of ax1.plot just because
SecondaryAxes inherits from _AxesBase, not from Axes, but that doesn't
really matter.)
Another advantage is that one can now use secondary_axis as a
replacement for SubplotZero, a relatively obscure feature of
mpl_toolkits that is only showcased in 3 examples:
https://matplotlib.org/gallery/axisartist/simple_axisline.htmlhttps://matplotlib.org/gallery/axisartist/simple_axisline2.htmlhttps://matplotlib.org/gallery/axisartist/demo_axisline_style.html
whose goal is just to draw a spine at x=0 or y=0.
simple_axisline2 just moves its main spine to y=0, so we can implement
that directly with Spine.set_position (see also simple_axisartist1).
simple_axisline adds additional spines, and I added an equivalent
implementation using secondary_axis, which is fairly transparent.
(This example, as well as test_secondary_xy, show why the axes patch
must be made invisible: otherwise, the patch of later secondary axes
would be drawn over other secondary axes.)
demo_axisline_style doesn't showcase anything that's specifically
related to SubplotZero so I just rewrote it without SubplotZero.
If we agree that secondary_axis is a suitable replacement, SubplotZero
could ultimately be deprecated (in a later PR).
Minor points:
Also delete `SecondaryAxis._loc`, which is set in a single place and
never used.
0 commit comments