Skip to content

Commit 6cee33c

Browse files
committed
axes_grid : doc update and new examples
svn path=/trunk/matplotlib/; revision=8010
1 parent 4fa9271 commit 6cee33c

File tree

10 files changed

+453
-6
lines changed

10 files changed

+453
-6
lines changed

doc/mpl_toolkits/axes_grid/api/axes_grid_api.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
:mod:`mpl_toolkits.axes_grid.axes_grid`
33
=======================================
44

5-
.. autoclass:: mpl_toolkits.axes_grid.axes_grid.AxesGrid
5+
.. autoclass:: mpl_toolkits.axes_grid.axes_grid.Grid
6+
:members:
7+
:undoc-members:
8+
9+
.. autoclass:: mpl_toolkits.axes_grid.axes_grid.ImageGrid
610
:members:
711
:undoc-members:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
:mod:`mpl_toolkits.axes_grid.axis_artist`
3+
=======================================
4+
5+
.. autoclass:: mpl_toolkits.axes_grid.axis_artist.AxisArtist
6+
:members:
7+
:undoc-members:
8+
9+
.. autoclass:: mpl_toolkits.axes_grid.axis_artist.Ticks
10+
:members:
11+
12+
.. autoclass:: mpl_toolkits.axes_grid.axis_artist.AxisLabel
13+
:members:
14+
15+
.. autoclass:: mpl_toolkits.axes_grid.axis_artist.TickLabels
16+
:members:

doc/mpl_toolkits/axes_grid/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
axes_size_api.rst
1313
axes_divider_api.rst
1414
axes_grid_api.rst
15+
axis_artist_api.rst
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
2+
3+
import numpy as np
4+
import mpl_toolkits.axes_grid.angle_helper as angle_helper
5+
import mpl_toolkits.axes_grid.grid_finder as grid_finder
6+
from matplotlib.projections import PolarAxes
7+
from matplotlib.transforms import Affine2D
8+
9+
import mpl_toolkits.axes_grid.axislines as axislines
10+
11+
from mpl_toolkits.axes_grid.grid_helper_curvelinear import GridHelperCurveLinear
12+
13+
14+
def setup_axes(fig, rect):
15+
"""
16+
polar projection, but in a rectangular box.
17+
"""
18+
19+
# see demo_curvelinear_grid.py for details
20+
tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform()
21+
22+
extreme_finder = angle_helper.ExtremeFinderCycle(20, 20,
23+
lon_cycle = 360,
24+
lat_cycle = None,
25+
lon_minmax = None,
26+
lat_minmax = (0, np.inf),
27+
)
28+
29+
grid_locator1 = angle_helper.LocatorDMS(12)
30+
grid_locator2 = grid_finder.MaxNLocator(5)
31+
32+
tick_formatter1 = angle_helper.FormatterDMS()
33+
34+
grid_helper = GridHelperCurveLinear(tr,
35+
extreme_finder=extreme_finder,
36+
grid_locator1=grid_locator1,
37+
grid_locator2=grid_locator2,
38+
tick_formatter1=tick_formatter1
39+
)
40+
41+
42+
ax1 = axislines.Subplot(fig, rect, grid_helper=grid_helper)
43+
ax1.axis[:].toggle(ticklabels=False)
44+
45+
fig.add_subplot(ax1)
46+
47+
ax1.set_aspect(1.)
48+
ax1.set_xlim(-5, 12)
49+
ax1.set_ylim(-5, 10)
50+
51+
#ax1.grid(True)
52+
53+
return ax1
54+
55+
56+
def add_floating_axis1(ax1):
57+
ax1.axis["lat"] = axis = ax1.new_floating_axis(0, 30)
58+
axis.label.set_text(r"$\theta = 30^{\circ}$")
59+
axis.label.set_visible(True)
60+
61+
return axis
62+
63+
64+
def add_floating_axis2(ax1):
65+
ax1.axis["lon"] = axis = ax1.new_floating_axis(1, 6)
66+
axis.label.set_text(r"$r = 6$")
67+
axis.label.set_visible(True)
68+
69+
return axis
70+
71+
72+
import matplotlib.pyplot as plt
73+
fig = plt.figure(1, figsize=(8, 4.))
74+
fig.clf()
75+
fig.subplots_adjust(left=0.01, right=0.99, bottom=0.01, top=0.99,
76+
wspace=0.01, hspace=0.01)
77+
78+
for i, d in enumerate(["bottom", "left", "top", "right"]):
79+
ax1 = setup_axes(fig, rect=241++i)
80+
axis = add_floating_axis1(ax1)
81+
axis.set_axis_direction(d)
82+
ax1.annotate(d, (0, 1), (5, -5),
83+
xycoords="axes fraction", textcoords="offset points",
84+
va="top", ha="left")
85+
86+
for i, d in enumerate(["bottom", "left", "top", "right"]):
87+
ax1 = setup_axes(fig, rect=245++i)
88+
axis = add_floating_axis2(ax1)
89+
axis.set_axis_direction(d)
90+
ax1.annotate(d, (0, 1), (5, -5),
91+
xycoords="axes fraction", textcoords="offset points",
92+
va="top", ha="left")
93+
94+
95+
96+
plt.show()
97+
98+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
3+
import matplotlib.pyplot as plt
4+
import mpl_toolkits.axes_grid.axislines as axislines
5+
6+
7+
def setup_axes(fig, rect):
8+
9+
ax = axislines.Subplot(fig, rect)
10+
fig.add_subplot(ax)
11+
12+
ax.set_yticks([0.2, 0.8])
13+
ax.set_yticklabels(["short", "loooong"])
14+
ax.set_xticks([0.2, 0.8])
15+
ax.set_xticklabels([r"$\frac{1}{2}\pi$", r"$\pi$"])
16+
17+
return ax
18+
19+
fig = plt.figure(1, figsize=(3, 5))
20+
fig.subplots_adjust(left=0.5, hspace=0.7)
21+
22+
23+
24+
ax = setup_axes(fig, 311)
25+
ax.set_ylabel("ha=right")
26+
ax.set_xlabel("va=baseline")
27+
28+
ax = setup_axes(fig, 312)
29+
ax.axis["left"].major_ticklabels.set_ha("center")
30+
ax.axis["bottom"].major_ticklabels.set_va("top")
31+
ax.set_ylabel("ha=center")
32+
ax.set_xlabel("va=top")
33+
34+
ax = setup_axes(fig, 313)
35+
ax.axis["left"].major_ticklabels.set_ha("left")
36+
ax.axis["bottom"].major_ticklabels.set_va("bottom")
37+
ax.set_ylabel("ha=left")
38+
ax.set_xlabel("va=bottom")
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
import matplotlib.pyplot as plt
3+
import mpl_toolkits.axes_grid.axislines as axislines
4+
5+
6+
def setup_axes(fig, rect):
7+
8+
ax = axislines.Subplot(fig, rect)
9+
fig.add_subplot(ax)
10+
11+
ax.set_yticks([0.2, 0.8])
12+
#ax.set_yticklabels(["short", "loooong"])
13+
ax.set_xticks([0.2, 0.8])
14+
#ax.set_xticklabels([r"$\frac{1}{2}\pi$", r"$\pi$"])
15+
16+
return ax
17+
18+
fig = plt.figure(1, figsize=(6, 3))
19+
fig.subplots_adjust(bottom=0.2)
20+
21+
22+
23+
ax = setup_axes(fig, 131)
24+
for axis in ax.axis.values(): axis.major_ticks.set_tick_out(True)
25+
#or you can simply do "ax.axis[:].major_ticks.set_tick_out(True)"
26+
27+
28+
29+
30+
ax = setup_axes(fig, 132)
31+
ax.axis["left"].set_axis_direction("right")
32+
ax.axis["bottom"].set_axis_direction("top")
33+
ax.axis["right"].set_axis_direction("left")
34+
ax.axis["top"].set_axis_direction("bottom")
35+
36+
ax.axis["left"].major_ticklabels.set_pad(0)
37+
ax.axis["bottom"].major_ticklabels.set_pad(10)
38+
39+
40+
41+
ax = setup_axes(fig, 133)
42+
ax.axis["left"].set_axis_direction("right")
43+
ax.axis[:].major_ticks.set_tick_out(True)
44+
45+
ax.axis["left"].label.set_text("Long Label Left")
46+
ax.axis["bottom"].label.set_text("Label Bottom")
47+
ax.axis["right"].label.set_text("Long Label Right")
48+
ax.axis["right"].label.set_visible(True)
49+
ax.axis["left"].label.set_pad(0)
50+
ax.axis["bottom"].label.set_pad(10)
51+
52+
plt.show()

doc/mpl_toolkits/axes_grid/users/axislines.rst

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ to not visible. As separate artists are used for rendering axis, some
4242
axis-related method in mpl may have no effect.
4343
In addition to AxisArtist instances, the axes_grid.axislines.Axes will
4444
have *gridlines* attribute (Gridlines), which obviously draws grid
45-
lines.
45+
lines.
4646

4747
In both AxisArtist and Gridlines, the calculation of tick and grid
4848
location is delegated to an instance of GridHelper class.
@@ -119,6 +119,43 @@ HowTo
119119

120120
ax.axis["left"].major_ticklabels.set_color("r")
121121

122+
3. To change the attributes of multiple axis::
123+
124+
ax.axis["left","bottom"].major_ticklabels.set_color("r")
125+
126+
or to change the attributes of all axis::
127+
128+
ax.axis[:].major_ticklabels.set_color("r")
129+
130+
4. To change the tick size (length), you need to use
131+
axis.major_ticks.set_ticksize method. To change the direction of
132+
the ticks (ticks are in opposite direction of ticklabels by
133+
default), use axis.major_ticks.set_tick_out method.
134+
135+
To change the pad between ticks and ticklabels, use
136+
axis.major_ticklabels.set_pad method.
137+
138+
To change the pad between ticklabels and axis label,
139+
axis.label.set_pad method.
140+
141+
Examples
142+
========
143+
144+
Adjusting axis_direction
145+
------------------------
146+
147+
.. plot:: mpl_toolkits/axes_grid/figures/demo_axis_direction.py
148+
149+
Adjusting ticklabels alignment
150+
------------------------------
151+
152+
.. plot:: mpl_toolkits/axes_grid/figures/demo_ticklabel_alignment.py
153+
154+
Adjusting ticklabels pad
155+
------------------------
156+
157+
.. plot:: mpl_toolkits/axes_grid/figures/demo_ticklabel_direction.py
158+
122159

123160
GridHelper
124161
==========
@@ -138,7 +175,7 @@ transform of the axes itself (ax.transData) is still rectlinear
138175
from mpl_toolkits.axes_grid.axislines import Subplot
139176

140177
# from curved coordinate to rectlinear coordinate.
141-
def tr(x, y):
178+
def tr(x, y):
142179
x, y = np.asarray(x), np.asarray(y)
143180
return x, y-x
144181

@@ -171,7 +208,7 @@ required. ::
171208

172209
# extreme finder : find a range of coordinate.
173210
# 20, 20 : number of sampling points along x, y direction
174-
# The first coordinate (longitude, but theta in polar)
211+
# The first coordinate (longitude, but theta in polar)
175212
# has a cycle of 360 degree.
176213
# The second coordinate (latitude, but radius in polar) has a minimum of 0
177214
extreme_finder = angle_helper.ExtremeFinderCycle(20, 20,
@@ -225,7 +262,7 @@ limits changes. A floating axis can be created using
225262
the resulting AxisArtist is properly added to the axes. A recommended
226263
way is to add it as an item of Axes's axis attribute.::
227264

228-
# floating axis whose first (index starts from 0) coordinate
265+
# floating axis whose first (index starts from 0) coordinate
229266
# (theta) is fixed at 60
230267

231268
ax1.axis["lat"] = axis = ax1.new_floating_axis(0, 60)

doc/mpl_toolkits/axes_grid/users/overview.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ratio. For example, displaying images of a same size with some fixed
3535
padding between them cannot be easily done in matplotlib. AxesGrid is
3636
used in such case.
3737

38-
.. plot:: mpl_examples/axes_grid/simple_axesgrid.py
38+
.. plot:: mpl_toolkits/axes_grid/examples/simple_axesgrid.py
3939
:include-source:
4040

4141
* The postion of each axes is determined at the drawing time (see
@@ -398,3 +398,11 @@ created. See :ref:`axislines-manual` for more details.
398398
.. plot:: mpl_toolkits/axes_grid/examples/demo_floating_axis.py
399399

400400

401+
Floating Axes
402+
=============
403+
404+
An axes whose outer axis are defined as floating axis.
405+
406+
.. plot:: mpl_toolkits/axes_grid/examples/demo_floating_axes.py
407+
408+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import numpy as np
2+
#from matplotlib.path import Path
3+
4+
import matplotlib.pyplot as plt
5+
6+
from mpl_toolkits.axes_grid.grid_helper_curvelinear import GridHelperCurveLinear
7+
from mpl_toolkits.axes_grid.axislines import Subplot
8+
9+
import mpl_toolkits.axes_grid.angle_helper as angle_helper
10+
11+
def curvelinear_test1(fig):
12+
"""
13+
grid for custom transform.
14+
"""
15+
16+
def tr(x, y):
17+
sgn = np.sign(x)
18+
x, y = np.abs(np.asarray(x)), np.asarray(y)
19+
return sgn*x**.5, y
20+
21+
def inv_tr(x,y):
22+
sgn = np.sign(x)
23+
x, y = np.asarray(x), np.asarray(y)
24+
return sgn*x**2, y
25+
26+
extreme_finder = angle_helper.ExtremeFinderCycle(20, 20,
27+
lon_cycle = None,
28+
lat_cycle = None,
29+
lon_minmax = None, #(0, np.inf),
30+
lat_minmax = None,
31+
)
32+
33+
grid_helper = GridHelperCurveLinear((tr, inv_tr),
34+
extreme_finder=extreme_finder)
35+
36+
ax1 = Subplot(fig, 111, grid_helper=grid_helper)
37+
# ax1 will have a ticks and gridlines defined by the given
38+
# transform (+ transData of the Axes). Note that the transform of
39+
# the Axes itself (i.e., transData) is not affected by the given
40+
# transform.
41+
42+
fig.add_subplot(ax1)
43+
44+
ax1.imshow(np.arange(25).reshape(5,5),
45+
vmax = 50, cmap=plt.cm.gray_r,
46+
interpolation="nearest",
47+
origin="lower")
48+
49+
# tick density
50+
grid_helper.grid_finder.grid_locator1._nbins = 6
51+
grid_helper.grid_finder.grid_locator2._nbins = 6
52+
53+
54+
55+
if 1:
56+
fig = plt.figure(1, figsize=(7, 4))
57+
fig.clf()
58+
59+
curvelinear_test1(fig)
60+
plt.show()
61+
62+
63+

0 commit comments

Comments
 (0)