Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Commitcfcd9a7
committed
Improve(?) implementation of secondary_axis.
Currently, secondary_xaxis is implemented by adding a child axes with aphysical height set to zero and y position set accordingly relative toits 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 usingSpine.set_position. It also makes sure that the secondary axes patch isinvisible and that the bounds of the "orthogonal" axis (the one that isnot shown) matches the parent bounds.By doing so, it becomes possible to plot data directly on the secondaryaxis as well; e.g. the following now works:```from matplotlib import pyplot as pltfrom matplotlib.axes import Axesfig, 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 becauseSecondaryAxes inherits from _AxesBase, not from Axes, but that doesn'treally matter.)Another advantage is that one can now use secondary_axis as areplacement for SubplotZero, a relatively obscure feature ofmpl_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.htmlwhose 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 implementthat directly with Spine.set_position (see also simple_axisartist1).simple_axisline adds additional spines, and I added an equivalentimplementation using secondary_axis, which is fairly transparent.(This example, as well as test_secondary_xy, show why the axes patchmust be made invisible: otherwise, the patch of later secondary axeswould be drawn over other secondary axes.)demo_axisline_style doesn't showcase anything that's specificallyrelated to SubplotZero so I just rewrote it without SubplotZero.If we agree that secondary_axis is a suitable replacement, SubplotZerocould ultimately be deprecated (in a later PR).Minor points:Also delete `SecondaryAxis._loc`, which is set in a single place andnever used.1 parentdb2193c commitcfcd9a7
File tree
5 files changed
+50
-58
lines changed- examples/axisartist
- lib/matplotlib/axes
5 files changed
+50
-58
lines changedLines changed: 4 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6 | 6 |
| |
7 | 7 |
| |
8 | 8 |
| |
9 |
| - | |
| 9 | + | |
10 | 10 |
| |
11 | 11 |
| |
12 | 12 |
| |
13 | 13 |
| |
14 | 14 |
| |
15 |
| - | |
| 15 | + | |
16 | 16 |
| |
17 | 17 |
| |
18 |
| - | |
19 |
| - | |
| 18 | + | |
20 | 19 |
| |
21 | 20 |
| |
22 |
| - | |
23 |
| - | |
24 |
| - | |
25 |
| - | |
26 |
| - | |
| 21 | + | |
27 | 22 |
| |
28 | 23 |
| |
29 | 24 |
| |
|
Lines changed: 6 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | 1 |
| |
2 |
| - | |
3 |
| - | |
4 |
| - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
5 | 5 |
| |
| 6 | + | |
| 7 | + | |
6 | 8 |
| |
| 9 | + | |
7 | 10 |
| |
8 | 11 |
| |
9 | 12 |
| |
|
Lines changed: 21 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
37 | 37 |
| |
38 | 38 |
| |
39 | 39 |
| |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
40 | 61 |
|
Lines changed: 7 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | 1 |
| |
2 |
| - | |
3 |
| - | |
4 |
| - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
5 | 5 |
| |
| 6 | + | |
| 7 | + | |
6 | 8 |
| |
| 9 | + | |
7 | 10 |
| |
8 | 11 |
| |
9 | 12 |
| |
10 | 13 |
| |
11 |
| - | |
| 14 | + | |
12 | 15 |
| |
13 | 16 |
| |
14 | 17 |
| |
|
Lines changed: 12 additions & 42 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
27 | 27 |
| |
28 | 28 |
| |
29 | 29 |
| |
30 |
| - | |
31 |
| - | |
32 |
| - | |
33 |
| - | |
34 |
| - | |
35 |
| - | |
36 |
| - | |
37 |
| - | |
38 |
| - | |
39 |
| - | |
40 |
| - | |
41 |
| - | |
42 |
| - | |
43 |
| - | |
44 |
| - | |
45 |
| - | |
46 |
| - | |
47 |
| - | |
48 |
| - | |
49 |
| - | |
50 |
| - | |
51 |
| - | |
52 |
| - | |
53 |
| - | |
54 |
| - | |
55 |
| - | |
56 |
| - | |
57 | 30 |
| |
58 | 31 |
| |
59 | 32 |
| |
| |||
86 | 59 |
| |
87 | 60 |
| |
88 | 61 |
| |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
89 | 68 |
| |
90 | 69 |
| |
91 | 70 |
| |
| |||
98 | 77 |
| |
99 | 78 |
| |
100 | 79 |
| |
| 80 | + | |
101 | 81 |
| |
102 | 82 |
| |
103 | 83 |
| |
| |||
161 | 141 |
| |
162 | 142 |
| |
163 | 143 |
| |
164 |
| - | |
165 |
| - | |
166 |
| - | |
167 |
| - | |
168 |
| - | |
169 |
| - | |
170 |
| - | |
171 |
| - | |
172 |
| - | |
173 |
| - | |
174 |
| - | |
175 |
| - | |
176 |
| - | |
177 |
| - | |
| 144 | + | |
| 145 | + | |
178 | 146 |
| |
179 | 147 |
| |
180 | 148 |
| |
| |||
290 | 258 |
| |
291 | 259 |
| |
292 | 260 |
| |
293 |
| - | |
| 261 | + | |
294 | 262 |
| |
295 | 263 |
| |
296 | 264 |
| |
297 | 265 |
| |
| 266 | + | |
298 | 267 |
| |
299 | 268 |
| |
300 | 269 |
| |
| 270 | + | |
301 | 271 |
| |
302 | 272 |
| |
303 | 273 |
| |
|
0 commit comments
Comments
(0)