Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc75b9b

Browse files
authored
Merge pull request #24207 from anntzer/dpa
2 parents 80b15fb + 24bcd30 commit cc75b9b

File tree

3 files changed

+34
-54
lines changed

3 files changed

+34
-54
lines changed

examples/axisartist/demo_parasite_axes.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
This approach uses `mpl_toolkits.axes_grid1.parasite_axes.HostAxes` and
1010
`mpl_toolkits.axes_grid1.parasite_axes.ParasiteAxes`.
1111
12-
An alternative approach using standard Matplotlib subplots is shown in the
13-
:doc:`/gallery/spines/multiple_yaxis_with_spines` example.
12+
The standard and recommended approach is to use instead standard Matplotlib
13+
axes, as shown in the :doc:`/gallery/spines/multiple_yaxis_with_spines`
14+
example.
1415
15-
An alternative approach using :mod:`mpl_toolkits.axes_grid1`
16-
and :mod:`mpl_toolkits.axisartist` is found in the
16+
An alternative approach using `mpl_toolkits.axes_grid1` and
17+
`mpl_toolkits.axisartist` is shown in the
1718
:doc:`/gallery/axisartist/demo_parasite_axes2` example.
1819
"""
1920

2021
from mpl_toolkits.axisartist.parasite_axes import HostAxes
2122
import matplotlib.pyplot as plt
2223

23-
2424
fig = plt.figure()
2525

2626
host = fig.add_axes([0.15, 0.1, 0.65, 0.8], axes_class=HostAxes)
@@ -39,15 +39,9 @@
3939
p2, = par1.plot([0, 1, 2], [0, 3, 2], label="Temperature")
4040
p3, = par2.plot([0, 1, 2], [50, 30, 15], label="Velocity")
4141

42-
host.set_xlim(0, 2)
43-
host.set_ylim(0, 2)
44-
par1.set_ylim(0, 4)
45-
par2.set_ylim(1, 65)
46-
47-
host.set_xlabel("Distance")
48-
host.set_ylabel("Density")
49-
par1.set_ylabel("Temperature")
50-
par2.set_ylabel("Velocity")
42+
host.set(xlim=(0, 2), ylim=(0, 2), xlabel="Distance", ylabel="Density")
43+
par1.set(ylim=(0, 4), ylabel="Temperature")
44+
par2.set(ylim=(1, 65), ylabel="Velocity")
5145

5246
host.legend()
5347

examples/axisartist/demo_parasite_axes2.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
of those two axis behave separately from each other: different datasets can be
1212
plotted, and the y-limits are adjusted separately.
1313
14-
Note that this approach uses the `mpl_toolkits.axes_grid1.parasite_axes`'
15-
`~mpl_toolkits.axes_grid1.parasite_axes.host_subplot` and
16-
`mpl_toolkits.axisartist.axislines.Axes`. An alternative approach using the
17-
`~mpl_toolkits.axes_grid1.parasite_axes`'s
18-
`~.mpl_toolkits.axes_grid1.parasite_axes.HostAxes` and
19-
`~.mpl_toolkits.axes_grid1.parasite_axes.ParasiteAxes` is the
14+
This approach uses `mpl_toolkits.axes_grid1.parasite_axes.host_subplot` and
15+
`mpl_toolkits.axisartist.axislines.Axes`.
16+
17+
The standard and recommended approach is to use instead standard Matplotlib
18+
axes, as shown in the :doc:`/gallery/spines/multiple_yaxis_with_spines`
19+
example.
20+
21+
An alternative approach using `mpl_toolkits.axes_grid1.parasite_axes.HostAxes`
22+
and `mpl_toolkits.axes_grid1.parasite_axes.ParasiteAxes` is shown in the
2023
:doc:`/gallery/axisartist/demo_parasite_axes` example.
21-
An alternative approach using the usual Matplotlib subplots is shown in
22-
the :doc:`/gallery/spines/multiple_yaxis_with_spines` example.
2324
"""
2425

2526
from mpl_toolkits.axes_grid1 import host_subplot
@@ -41,15 +42,9 @@
4142
p2, = par1.plot([0, 1, 2], [0, 3, 2], label="Temperature")
4243
p3, = par2.plot([0, 1, 2], [50, 30, 15], label="Velocity")
4344

44-
host.set_xlim(0, 2)
45-
host.set_ylim(0, 2)
46-
par1.set_ylim(0, 4)
47-
par2.set_ylim(1, 65)
48-
49-
host.set_xlabel("Distance")
50-
host.set_ylabel("Density")
51-
par1.set_ylabel("Temperature")
52-
par2.set_ylabel("Velocity")
45+
host.set(xlim=(0, 2), ylim=(0, 2), xlabel="Distance", ylabel="Density")
46+
par1.set(ylim=(0, 4), ylabel="Temperature")
47+
par2.set(ylim=(1, 65), ylabel="Velocity")
5348

5449
host.legend()
5550

examples/spines/multiple_yaxis_with_spines.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
r"""
2-
==========================
3-
Multiple Yaxis With Spines
4-
==========================
2+
===========================
3+
Multiple y-axis with Spines
4+
===========================
55
66
Create multiple y axes with a shared x axis. This is done by creating
77
a `~.axes.Axes.twinx` axes, turning all spines but the right one invisible
88
and offset its position using `~.spines.Spine.set_position`.
99
1010
Note that this approach uses `matplotlib.axes.Axes` and their
11-
`~matplotlib.spines.Spine`\s. An alternative approach for parasite
12-
axes is shown in the :doc:`/gallery/axisartist/demo_parasite_axes` and
11+
`~matplotlib.spines.Spine`\s. Alternative approaches using non-standard axes
12+
are shown in the :doc:`/gallery/axisartist/demo_parasite_axes` and
1313
:doc:`/gallery/axisartist/demo_parasite_axes2` examples.
1414
"""
1515

1616
import matplotlib.pyplot as plt
1717

18-
1918
fig, ax = plt.subplots()
2019
fig.subplots_adjust(right=0.75)
2120

@@ -26,29 +25,21 @@
2625
# placed on the right by twinx above.
2726
twin2.spines.right.set_position(("axes", 1.2))
2827

29-
p1, = ax.plot([0, 1, 2], [0, 1, 2], "b-", label="Density")
30-
p2, = twin1.plot([0, 1, 2], [0, 3, 2], "r-", label="Temperature")
31-
p3, = twin2.plot([0, 1, 2], [50, 30, 15], "g-", label="Velocity")
32-
33-
ax.set_xlim(0, 2)
34-
ax.set_ylim(0, 2)
35-
twin1.set_ylim(0, 4)
36-
twin2.set_ylim(1, 65)
28+
p1, = ax.plot([0, 1, 2], [0, 1, 2], "C0", label="Density")
29+
p2, = twin1.plot([0, 1, 2], [0, 3, 2], "C1", label="Temperature")
30+
p3, = twin2.plot([0, 1, 2], [50, 30, 15], "C2", label="Velocity")
3731

38-
ax.set_xlabel("Distance")
39-
ax.set_ylabel("Density")
40-
twin1.set_ylabel("Temperature")
41-
twin2.set_ylabel("Velocity")
32+
ax.set(xlim=(0, 2), ylim=(0, 2), xlabel="Distance", ylabel="Density")
33+
twin1.set(ylim=(0, 4), ylabel="Temperature")
34+
twin2.set(ylim=(1, 65), ylabel="Velocity")
4235

4336
ax.yaxis.label.set_color(p1.get_color())
4437
twin1.yaxis.label.set_color(p2.get_color())
4538
twin2.yaxis.label.set_color(p3.get_color())
4639

47-
tkw = dict(size=4, width=1.5)
48-
ax.tick_params(axis='y', colors=p1.get_color(), **tkw)
49-
twin1.tick_params(axis='y', colors=p2.get_color(), **tkw)
50-
twin2.tick_params(axis='y', colors=p3.get_color(), **tkw)
51-
ax.tick_params(axis='x', **tkw)
40+
ax.tick_params(axis='y', colors=p1.get_color())
41+
twin1.tick_params(axis='y', colors=p2.get_color())
42+
twin2.tick_params(axis='y', colors=p3.get_color())
5243

5344
ax.legend(handles=[p1, p2, p3])
5445

0 commit comments

Comments
 (0)