Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a9c4070

Browse filesBrowse files
committed
Cleanup new_fixed_axis examples.
- We can call new_fixed_axis directly on the axes instance, which will forward the call to the grid_helper and also correctly set the *axes* kwarg. - In demo_parasite_axes and demo_parasite_axes2, group together the limits and labels settings, and remove some duplicates. - Reword the description of demo_parasite_axes2.
1 parent ad76c83 commit a9c4070
Copy full SHA for a9c4070

File tree

Expand file treeCollapse file tree

3 files changed

+31
-46
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+31
-46
lines changed

‎examples/axisartist/demo_parasite_axes.py

Copy file name to clipboardExpand all lines: examples/axisartist/demo_parasite_axes.py
+9-16Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,30 @@
2929
host.parasites.append(par1)
3030
host.parasites.append(par2)
3131

32-
host.set_ylabel("Density")
33-
host.set_xlabel("Distance")
34-
3532
host.axis["right"].set_visible(False)
36-
par1.axis["right"].set_visible(True)
37-
par1.set_ylabel("Temperature")
3833

34+
par1.axis["right"].set_visible(True)
3935
par1.axis["right"].major_ticklabels.set_visible(True)
4036
par1.axis["right"].label.set_visible(True)
4137

42-
par2.set_ylabel("Velocity")
43-
offset = (60, 0)
44-
new_axisline = par2.get_grid_helper().new_fixed_axis
45-
par2.axis["right2"] = new_axisline(loc="right", axes=par2, offset=offset)
38+
par2.axis["right2"] = par2.new_fixed_axis(loc="right", offset=(60, 0))
4639

4740
fig.add_axes(host)
4841

49-
host.set_xlim(0, 2)
50-
host.set_ylim(0, 2)
51-
52-
host.set_xlabel("Distance")
53-
host.set_ylabel("Density")
54-
par1.set_ylabel("Temperature")
55-
5642
p1, = host.plot([0, 1, 2], [0, 1, 2], label="Density")
5743
p2, = par1.plot([0, 1, 2], [0, 3, 2], label="Temperature")
5844
p3, = par2.plot([0, 1, 2], [50, 30, 15], label="Velocity")
5945

46+
host.set_xlim(0, 2)
47+
host.set_ylim(0, 2)
6048
par1.set_ylim(0, 4)
6149
par2.set_ylim(1, 65)
6250

51+
host.set_xlabel("Distance")
52+
host.set_ylabel("Density")
53+
par1.set_ylabel("Temperature")
54+
par2.set_ylabel("Velocity")
55+
6356
host.legend()
6457

6558
host.axis["left"].label.set_color(p1.get_color())

‎examples/axisartist/demo_parasite_axes2.py

Copy file name to clipboardExpand all lines: examples/axisartist/demo_parasite_axes2.py
+20-25Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
"""
2-
===================
3-
Demo Parasite Axes2
4-
===================
5-
2+
==================
63
Parasite axis demo
4+
==================
5+
6+
This example demonstrates the use of parasite axis to plot multiple datasets
7+
onto one single plot.
78
8-
The following code is an example of a parasite axis. It aims to show how
9-
to plot multiple different values onto one single plot. Notice how in this
10-
example, par1 and par2 are both calling twinx meaning both are tied directly to
11-
the x-axis. From there, each of those two axis can behave separately from the
12-
each other, meaning they can take on separate values from themselves as well as
13-
the x-axis.
9+
Notice how in this example, *par1* and *par2* are both obtained by calling
10+
``twinx()``, which ties their x-limits with the host's x-axis. From there, each
11+
of those two axis behave separately from each other: different datasets can be
12+
plotted, and the y-limits are adjusted separately.
1413
15-
Note that this approach uses the `mpl_toolkits.axes_grid1.parasite_axes`\'
14+
Note that this approach uses the `mpl_toolkits.axes_grid1.parasite_axes`'
1615
`~mpl_toolkits.axes_grid1.parasite_axes.host_subplot` and
1716
`mpl_toolkits.axisartist.axislines.Axes`. An alternative approach using the
18-
`~mpl_toolkits.axes_grid1.parasite_axes`\'s
17+
`~mpl_toolkits.axes_grid1.parasite_axes`'s
1918
`~.mpl_toolkits.axes_grid1.parasite_axes.HostAxes` and
2019
`~.mpl_toolkits.axes_grid1.parasite_axes.ParasiteAxes` is the
2120
:doc:`/gallery/axisartist/demo_parasite_axes` example.
22-
An alternative approach using the usual matplotlib subplots is shown in
21+
An alternative approach using the usual Matplotlib subplots is shown in
2322
the :doc:`/gallery/ticks_and_spines/multiple_yaxis_with_spines` example.
2423
"""
24+
2525
from mpl_toolkits.axes_grid1 import host_subplot
2626
from mpl_toolkits import axisartist
2727
import matplotlib.pyplot as plt
@@ -32,30 +32,25 @@
3232
par1 = host.twinx()
3333
par2 = host.twinx()
3434

35-
offset = 60
36-
new_fixed_axis = par2.get_grid_helper().new_fixed_axis
37-
par2.axis["right"] = new_fixed_axis(loc="right",
38-
axes=par2,
39-
offset=(offset, 0))
35+
par2.axis["right"] = par2.new_fixed_axis(loc="right", offset=(60, 0))
4036

4137
par1.axis["right"].toggle(all=True)
4238
par2.axis["right"].toggle(all=True)
4339

40+
p1, = host.plot([0, 1, 2], [0, 1, 2], label="Density")
41+
p2, = par1.plot([0, 1, 2], [0, 3, 2], label="Temperature")
42+
p3, = par2.plot([0, 1, 2], [50, 30, 15], label="Velocity")
43+
4444
host.set_xlim(0, 2)
4545
host.set_ylim(0, 2)
46+
par1.set_ylim(0, 4)
47+
par2.set_ylim(1, 65)
4648

4749
host.set_xlabel("Distance")
4850
host.set_ylabel("Density")
4951
par1.set_ylabel("Temperature")
5052
par2.set_ylabel("Velocity")
5153

52-
p1, = host.plot([0, 1, 2], [0, 1, 2], label="Density")
53-
p2, = par1.plot([0, 1, 2], [0, 3, 2], label="Temperature")
54-
p3, = par2.plot([0, 1, 2], [50, 30, 15], label="Velocity")
55-
56-
par1.set_ylim(0, 4)
57-
par2.set_ylim(1, 65)
58-
5954
host.legend()
6055

6156
host.axis["left"].label.set_color(p1.get_color())

‎examples/axisartist/simple_axisline.py

Copy file name to clipboardExpand all lines: examples/axisartist/simple_axisline.py
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
===============
55
66
"""
7-
import matplotlib.pyplot as plt
87

8+
import matplotlib.pyplot as plt
99
from mpl_toolkits.axisartist.axislines import SubplotZero
1010

1111

@@ -30,10 +30,7 @@
3030
#ax.axis["left"].label.set_text("Label Y")
3131

3232
# make new (right-side) yaxis, but with some offset
33-
offset = (20, 0)
34-
new_axisline = ax.get_grid_helper().new_fixed_axis
35-
36-
ax.axis["right2"] = new_axisline(loc="right", offset=offset, axes=ax)
33+
ax.axis["right2"] = ax.new_fixed_axis(loc="right", offset=(20, 0))
3734
ax.axis["right2"].label.set_text("Label Y2")
3835

3936
ax.plot([-2, 3, 2])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.