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

Skip to content

Commit 4833e41

Browse files
committed
Merge pull request #7298 from sirlittle/master
Changed Examples for Pep8 Compliance
1 parent 83292f5 commit 4833e41

File tree

2 files changed

+56
-46
lines changed

2 files changed

+56
-46
lines changed

examples/axes_grid/demo_floating_axis.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
"""
2-
An experimental support for curvilinear grid.
2+
Axis within rectangular frame
3+
4+
The following code demonstrates how to put a floating
5+
polar curve within a rectangular box. In order to get
6+
a better sense of polar curves, please look at
7+
demo_curvelinear_grid.py.
38
"""
9+
import numpy as np
10+
import matplotlib.pyplot as plt
11+
import mpl_toolkits.axisartist.angle_helper as angle_helper
12+
from matplotlib.projections import PolarAxes
13+
from matplotlib.transforms import Affine2D
14+
from mpl_toolkits.axisartist import SubplotHost
15+
from mpl_toolkits.axisartist import GridHelperCurveLinear
416

517

618
def curvelinear_test2(fig):
719
"""
820
polar projection, but in a rectangular box.
921
"""
1022
global ax1
11-
import numpy as np
12-
import mpl_toolkits.axisartist.angle_helper as angle_helper
13-
from matplotlib.projections import PolarAxes
14-
from matplotlib.transforms import Affine2D
15-
16-
from mpl_toolkits.axisartist import SubplotHost
17-
18-
from mpl_toolkits.axisartist import GridHelperCurveLinear
19-
2023
# see demo_curvelinear_grid.py for details
21-
tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform()
24+
tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform()
2225

23-
extreme_finder = angle_helper.ExtremeFinderCycle(20, 20,
26+
extreme_finder = angle_helper.ExtremeFinderCycle(20,
27+
20,
2428
lon_cycle=360,
2529
lat_cycle=None,
2630
lon_minmax=None,
27-
lat_minmax=(0, np.inf),
31+
lat_minmax=(0,
32+
np.inf),
2833
)
2934

3035
grid_locator1 = angle_helper.LocatorDMS(12)
@@ -43,7 +48,6 @@ def curvelinear_test2(fig):
4348

4449
# Now creates floating axis
4550

46-
#grid_helper = ax1.get_grid_helper()
4751
# floating axis whose first coordinate (theta) is fixed at 60
4852
ax1.axis["lat"] = axis = ax1.new_floating_axis(0, 60)
4953
axis.label.set_text(r"$\theta = 60^{\circ}$")
@@ -59,7 +63,6 @@ def curvelinear_test2(fig):
5963

6064
ax1.grid(True)
6165

62-
import matplotlib.pyplot as plt
6366
fig = plt.figure(1, figsize=(5, 5))
6467
fig.clf()
6568

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,52 @@
1+
"""
2+
Parasite axis demo
3+
4+
The following code is an example of a parasite axis.
5+
It aims to show a user how to plot multiple different values
6+
onto one single plot. Notice how in this example, par1 and
7+
par2 are both calling twinx meaning both are tied directly to
8+
the x-axis. From there, each of those two axis can behave
9+
separately from the each other, meaning they can take on
10+
seperate values from themselves as well as the x-axis.
11+
"""
112
from mpl_toolkits.axes_grid1 import host_subplot
213
import mpl_toolkits.axisartist as AA
314
import matplotlib.pyplot as plt
415

5-
if 1:
16+
host = host_subplot(111, axes_class=AA.Axes)
17+
plt.subplots_adjust(right=0.75)
618

7-
host = host_subplot(111, axes_class=AA.Axes)
8-
plt.subplots_adjust(right=0.75)
19+
par1 = host.twinx()
20+
par2 = host.twinx()
921

10-
par1 = host.twinx()
11-
par2 = host.twinx()
22+
offset = 60
23+
new_fixed_axis = par2.get_grid_helper().new_fixed_axis
24+
par2.axis["right"] = new_fixed_axis(loc="right",
25+
axes=par2,
26+
offset=(offset, 0))
1227

13-
offset = 60
14-
new_fixed_axis = par2.get_grid_helper().new_fixed_axis
15-
par2.axis["right"] = new_fixed_axis(loc="right",
16-
axes=par2,
17-
offset=(offset, 0))
28+
par2.axis["right"].toggle(all=True)
1829

19-
par2.axis["right"].toggle(all=True)
30+
host.set_xlim(0, 2)
31+
host.set_ylim(0, 2)
2032

21-
host.set_xlim(0, 2)
22-
host.set_ylim(0, 2)
33+
host.set_xlabel("Distance")
34+
host.set_ylabel("Density")
35+
par1.set_ylabel("Temperature")
36+
par2.set_ylabel("Velocity")
2337

24-
host.set_xlabel("Distance")
25-
host.set_ylabel("Density")
26-
par1.set_ylabel("Temperature")
27-
par2.set_ylabel("Velocity")
38+
p1, = host.plot([0, 1, 2], [0, 1, 2], label="Density")
39+
p2, = par1.plot([0, 1, 2], [0, 3, 2], label="Temperature")
40+
p3, = par2.plot([0, 1, 2], [50, 30, 15], label="Velocity")
2841

29-
p1, = host.plot([0, 1, 2], [0, 1, 2], label="Density")
30-
p2, = par1.plot([0, 1, 2], [0, 3, 2], label="Temperature")
31-
p3, = par2.plot([0, 1, 2], [50, 30, 15], label="Velocity")
42+
par1.set_ylim(0, 4)
43+
par2.set_ylim(1, 65)
3244

33-
par1.set_ylim(0, 4)
34-
par2.set_ylim(1, 65)
45+
host.legend()
3546

36-
host.legend()
47+
host.axis["left"].label.set_color(p1.get_color())
48+
par1.axis["right"].label.set_color(p2.get_color())
49+
par2.axis["right"].label.set_color(p3.get_color())
3750

38-
host.axis["left"].label.set_color(p1.get_color())
39-
par1.axis["right"].label.set_color(p2.get_color())
40-
par2.axis["right"].label.set_color(p3.get_color())
41-
42-
plt.draw()
43-
plt.show()
44-
45-
#plt.savefig("Test")
51+
plt.draw()
52+
plt.show()

0 commit comments

Comments
 (0)