Skip to content

Commit 3d6d64b

Browse files
committed
update demo_floating_axes.py
svn path=/trunk/matplotlib/; revision=8031
1 parent 1113012 commit 3d6d64b

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

examples/axes_grid/demo_floating_axes.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,27 @@
1010
DictFormatter
1111

1212
def setup_axes1(fig, rect):
13+
"""
14+
A simple one.
15+
"""
16+
tr = Affine2D().scale(2, 1).rotate_deg(30)
17+
18+
grid_helper = GridHelperCurveLinear(tr, extremes=(0, 4, 0, 4))
19+
20+
ax1 = FloatingSubplot(fig, rect, grid_helper=grid_helper)
21+
fig.add_subplot(ax1)
22+
23+
grid_helper.grid_finder.grid_locator1._nbins = 4
24+
grid_helper.grid_finder.grid_locator2._nbins = 4
25+
26+
return ax1
27+
28+
29+
def setup_axes2(fig, rect):
30+
"""
31+
With custom locator and formatter.
32+
Note that the extreme values are swapped.
33+
"""
1334

1435
#tr_scale = Affine2D().scale(np.pi/180., 1.)
1536

@@ -26,8 +47,6 @@ def setup_axes1(fig, rect):
2647

2748
grid_helper = GridHelperCurveLinear(tr,
2849
extremes=(.5*pi, 0, 2, 1),
29-
#extremes=(0, .5*pi, 1, 2),
30-
#extremes=(0, 1, 1, 2),
3150
grid_locator1=grid_locator1,
3251
grid_locator2=grid_locator2,
3352
tick_formatter1=tick_formatter1,
@@ -37,8 +56,6 @@ def setup_axes1(fig, rect):
3756
ax1 = FloatingSubplot(fig, rect, grid_helper=grid_helper)
3857
fig.add_subplot(ax1)
3958

40-
#ax1.axis[:]
41-
4259
# create a parasite axes whose transData in RA, cz
4360
aux_ax = ax1.get_aux_axes(tr)
4461

@@ -51,7 +68,10 @@ def setup_axes1(fig, rect):
5168
return ax1, aux_ax
5269

5370

54-
def setup_axes2(fig, rect):
71+
def setup_axes3(fig, rect):
72+
"""
73+
Sometimes, things like axis_direction need to be adjusted.
74+
"""
5575

5676
# rotate a bit for better orientation
5777
tr_rotate = Affine2D().translate(-95, 0)
@@ -105,26 +125,31 @@ def setup_axes2(fig, rect):
105125
return ax1, aux_ax
106126

107127

108-
def sixty(d, m, s):
109-
return d + (m + s/60.)/60.
110-
111-
112128

113129
if 1:
114130
import matplotlib.pyplot as plt
115-
fig = plt.figure(1, figsize=(7, 5))
131+
fig = plt.figure(1, figsize=(8, 4))
132+
fig.subplots_adjust(wspace=0.3, left=0.05, right=0.95)
133+
134+
ax1 = setup_axes1(fig, 131)
135+
136+
#theta = np.random.rand(10) #*.5*np.pi
137+
#radius = np.random.rand(10) #+1.
138+
#aux_ax1.scatter(theta, radius)
116139

117-
ax1, aux_ax1 = setup_axes1(fig, 121)
140+
141+
ax2, aux_ax2 = setup_axes2(fig, 132)
118142

119143
theta = np.random.rand(10)*.5*np.pi
120144
radius = np.random.rand(10)+1.
121-
aux_ax1.scatter(theta, radius)
145+
aux_ax2.scatter(theta, radius)
122146

123-
ax2, aux_ax2 = setup_axes2(fig, 122)
147+
148+
ax3, aux_ax3 = setup_axes3(fig, 133)
124149

125150
theta = (8 + np.random.rand(10)*(14-8))*15. # indegree
126151
radius = np.random.rand(10)*14000.
127-
aux_ax2.scatter(theta, radius)
152+
aux_ax3.scatter(theta, radius)
128153

129154
plt.show()
130155

0 commit comments

Comments
 (0)