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

Skip to content

Commit d7894c1

Browse files
committed
axes_grid : minor improvements in anchored_artists and inset_locator.
svn path=/trunk/matplotlib/; revision=7261
1 parent d1b07c0 commit d7894c1

File tree

5 files changed

+76
-41
lines changed

5 files changed

+76
-41
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2009-07-14 axes_grid : minor improvements in anchored_artists and
2+
inset_locator. -JJL
3+
14
2009-07-14 Fix a few bugs in ConnectionStyle algorithms. Add
25
ConnectionPatch class. -JJL
36

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
"""
2-
AxesGrid
3-
"""
4-
51
import axes_size as Size
62
from axes_divider import Divider, SubplotDivider, LocatableAxes, \
73
make_axes_locatable
8-
from axes_grid import AxesGrid
4+
from axes_grid import Grid, ImageGrid, AxesGrid
95
#from axes_divider import make_axes_locatable
106

lib/mpl_toolkits/axes_grid/anchored_artists.py

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,37 @@ def __init__(self, s, loc, pad=0.4, borderpad=0.5, prop=None, **kwargs):
2121
**kwargs)
2222

2323

24-
class AnchoredSizeBar(AnchoredOffsetbox):
25-
def __init__(self, transform, size, label, loc,
26-
pad=0.1, borderpad=0.1, sep=2, prop=None, frameon=True):
27-
"""
28-
Draw a horizontal bar with the size in data coordinate of the give axes.
29-
A label will be drawn underneath (center-alinged).
3024

31-
pad, borderpad in fraction of the legend font size (or prop)
32-
sep in points.
33-
"""
34-
self.size_bar = AuxTransformBox(transform)
35-
self.size_bar.add_artist(Rectangle((0,0), size, 0, fc="none"))
25+
class AnchoredDrawingArea(AnchoredOffsetbox):
26+
def __init__(self, width, height, xdescent, ydescent,
27+
loc, pad=0.4, borderpad=0.5, prop=None, frameon=True,
28+
**kwargs):
3629

37-
self.txt_label = TextArea(label, minimumdescent=False)
30+
self.da = DrawingArea(width, height, xdescent, ydescent, clip=True)
31+
self.drawing_area = self.da
32+
33+
super(AnchoredDrawingArea, self).__init__(loc, pad=pad, borderpad=borderpad,
34+
child=self.da,
35+
prop=None,
36+
frameon=frameon,
37+
**kwargs)
3838

39-
self._box = VPacker(children=[self.size_bar, self.txt_label],
40-
align="center",
41-
pad=0, sep=sep)
39+
class AnchoredAuxTransformBox(AnchoredOffsetbox):
40+
def __init__(self, transform, loc,
41+
pad=0.4, borderpad=0.5, prop=None, frameon=True, **kwargs):
42+
43+
self.drawing_area = AuxTransformBox(transform)
4244

4345
AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,
44-
child=self._box,
46+
child=self.drawing_area,
4547
prop=prop,
46-
frameon=frameon)
48+
frameon=frameon,
49+
**kwargs)
4750

4851

4952
class AnchoredEllipse(AnchoredOffsetbox):
5053
def __init__(self, transform, width, height, angle, loc,
51-
pad=0.1, borderpad=0.1, prop=None, frameon=True):
54+
pad=0.1, borderpad=0.1, prop=None, frameon=True, **kwargs):
5255
"""
5356
Draw an ellipse the size in data coordinate of the give axes.
5457
@@ -61,20 +64,32 @@ def __init__(self, transform, width, height, angle, loc,
6164
AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,
6265
child=self._box,
6366
prop=prop,
64-
frameon=frameon)
67+
frameon=frameon, **kwargs)
6568

6669

6770

68-
class AnchoredDrawingArea(AnchoredOffsetbox):
69-
def __init__(self, width, height, xdescent, ydescent,
70-
loc, pad=0.4, borderpad=0.5, prop=None, frameon=True):
71+
class AnchoredSizeBar(AnchoredOffsetbox):
72+
def __init__(self, transform, size, label, loc,
73+
pad=0.1, borderpad=0.1, sep=2, prop=None, frameon=True,
74+
**kwargs):
75+
"""
76+
Draw a horizontal bar with the size in data coordinate of the give axes.
77+
A label will be drawn underneath (center-alinged).
7178
72-
self.da = DrawingArea(width, height, xdescent, ydescent, clip=True)
79+
pad, borderpad in fraction of the legend font size (or prop)
80+
sep in points.
81+
"""
82+
self.size_bar = AuxTransformBox(transform)
83+
self.size_bar.add_artist(Rectangle((0,0), size, 0, fc="none"))
7384

74-
super(AnchoredDrawingArea, self).__init__(loc, pad=pad, borderpad=borderpad,
75-
child=self.da,
76-
prop=None,
77-
frameon=frameon)
85+
self.txt_label = TextArea(label, minimumdescent=False)
7886

87+
self._box = VPacker(children=[self.size_bar, self.txt_label],
88+
align="center",
89+
pad=0, sep=sep)
7990

91+
AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,
92+
child=self._box,
93+
prop=prop,
94+
frameon=frameon, **kwargs)
8095

lib/mpl_toolkits/axes_grid/axes_grid.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def __init__(self, fig,
168168
axes_class=None,
169169
):
170170
"""
171-
Build an :class:`AxesGrid` instance with a grid nrows*ncols
171+
Build an :class:`Grid` instance with a grid nrows*ncols
172172
:class:`~matplotlib.axes.Axes` in
173173
:class:`~matplotlib.figure.Figure` *fig* with
174174
*rect=[left, bottom, width, height]* (in
@@ -184,7 +184,8 @@ def __init__(self, fig,
184184
axes_pad 0.02 float| pad betweein axes given in inches
185185
add_all True [ True | False ]
186186
share_all False [ True | False ]
187-
aspect True [ True | False ]
187+
share_x True [ True | False ]
188+
share_y True [ True | False ]
188189
label_mode "L" [ "L" | "1" | "all" ]
189190
axes_class None a type object which must be a subclass
190191
of :class:`~matplotlib.axes.Axes`
@@ -406,14 +407,14 @@ def set_label_mode(self, mode):
406407
_tick_only(ax, bottom_on=False, left_on=False)
407408

408409

409-
class AxesGrid(Grid):
410+
class ImageGrid(Grid):
410411
"""
411412
A class that creates a grid of Axes. In matplotlib, the axes
412413
location (and size) is specified in the normalized figure
413414
coordinates. This may not be ideal for images that needs to be
414415
displayed with a given aspect ratio. For example, displaying
415416
images of a same size with some fixed padding between them cannot
416-
be easily done in matplotlib. AxesGrid is used in such case.
417+
be easily done in matplotlib. ImageGrid is used in such case.
417418
"""
418419

419420
def __init__(self, fig,
@@ -433,7 +434,7 @@ def __init__(self, fig,
433434
axes_class=None,
434435
):
435436
"""
436-
Build an :class:`AxesGrid` instance with a grid nrows*ncols
437+
Build an :class:`ImageGrid` instance with a grid nrows*ncols
437438
:class:`~matplotlib.axes.Axes` in
438439
:class:`~matplotlib.figure.Figure` *fig* with
439440
*rect=[left, bottom, width, height]* (in
@@ -661,6 +662,7 @@ def _update_locators(self):
661662
self._divider.set_vertical(v)
662663

663664

665+
AxesGrid = ImageGrid
664666

665667

666668

@@ -689,7 +691,7 @@ def _update_locators(self):
689691

690692
F.subplots_adjust(left=0.05, right=0.98)
691693

692-
grid = AxesGrid(F, 131, # similar to subplot(111)
694+
grid = ImageGrid(F, 131, # similar to subplot(111)
693695
nrows_ncols = (2, 2),
694696
direction="row",
695697
axes_pad = 0.05,
@@ -708,7 +710,7 @@ def _update_locators(self):
708710
plt.ion()
709711

710712

711-
grid = AxesGrid(F, 132, # similar to subplot(111)
713+
grid = ImageGrid(F, 132, # similar to subplot(111)
712714
nrows_ncols = (2, 2),
713715
direction="row",
714716
axes_pad = 0.0,
@@ -733,7 +735,7 @@ def _update_locators(self):
733735

734736

735737

736-
grid = AxesGrid(F, 133, # similar to subplot(122)
738+
grid = ImageGrid(F, 133, # similar to subplot(122)
737739
nrows_ncols = (2, 2),
738740
direction="row",
739741
axes_pad = 0.1,

lib/mpl_toolkits/axes_grid/inset_locator.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,23 @@ def get_path(self):
239239
self.loc1, self.loc2)
240240

241241

242+
class BboxConnectorPatch(BboxConnector):
243+
244+
def __init__(self, bbox1, bbox2, loc1a, loc2a, loc1b, loc2b, **kwargs):
245+
if "transform" in kwargs:
246+
raise ValueError("transform should not be set")
247+
BboxConnector.__init__(self, bbox1, bbox2, loc1a, loc2a, **kwargs)
248+
self.loc1b = loc1b
249+
self.loc2b = loc2b
250+
251+
def get_path(self):
252+
path1 = self.connect_bbox(self.bbox1, self.bbox2, self.loc1, self.loc2)
253+
path2 = self.connect_bbox(self.bbox2, self.bbox1, self.loc2b, self.loc1b)
254+
path_merged = list(path1.vertices) + list (path2.vertices) + [path1.vertices[0]]
255+
return Path(path_merged)
256+
257+
258+
242259
def _add_inset_axes(parent_axes, inset_axes):
243260
parent_axes.figure.add_axes(inset_axes)
244261
inset_axes.set_navigate(False)
@@ -285,7 +302,9 @@ def zoomed_inset_axes(parent_axes, zoom, loc=1,
285302
inset_axes = axes_class(parent_axes.figure, parent_axes.get_position(),
286303
**axes_kwargs)
287304

288-
axes_locator = AnchoredZoomLocator(parent_axes, zoom=zoom, loc=loc)
305+
axes_locator = AnchoredZoomLocator(parent_axes, zoom=zoom, loc=loc,
306+
bbox_to_anchor=None, bbox_transform=None,
307+
**kwargs)
289308
inset_axes.set_axes_locator(axes_locator)
290309

291310
_add_inset_axes(parent_axes, inset_axes)

0 commit comments

Comments
 (0)