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

Skip to content

Commit 38a32f1

Browse files
committed
Add tests for ImageGrid
1 parent a413677 commit 38a32f1

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

lib/mpl_toolkits/axes_grid1/axes_grid.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ def __init__(self, fig,
8383
----------
8484
fig : `.Figure`
8585
The parent figure.
86-
rect : (float, float, float, float) or int
87-
The axes position, as a ``(left, bottom, width, height)`` tuple or
88-
as a three-digit subplot position code (e.g., "121").
86+
rect : (float, float, float, float), (int, int, int), int, or \
87+
`~.SubplotSpec`
88+
The axes position, as a ``(left, bottom, width, height)`` tuple,
89+
as a three-digit subplot position code (e.g., ``(1, 2, 1)`` or
90+
``121``), or as a `~.SubplotSpec`.
8991
nrows_ncols : (int, int)
9092
Number of rows and columns in the grid.
9193
ngrids : int or None, default: None
@@ -141,7 +143,7 @@ def __init__(self, fig,
141143
axes_class = functools.partial(cls, **kwargs)
142144

143145
kw = dict(horizontal=[], vertical=[], aspect=aspect)
144-
if isinstance(rect, (str, Number, SubplotSpec)):
146+
if isinstance(rect, (Number, SubplotSpec)):
145147
self._divider = SubplotDivider(fig, rect, **kw)
146148
elif len(rect) == 3:
147149
self._divider = SubplotDivider(fig, *rect, **kw)

lib/mpl_toolkits/tests/test_axes_grid1.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from mpl_toolkits.axes_grid1.anchored_artists import (
1818
AnchoredSizeBar, AnchoredDirectionArrows)
1919
from mpl_toolkits.axes_grid1.axes_divider import (
20-
Divider, HBoxDivider, make_axes_area_auto_adjustable)
20+
Divider, HBoxDivider, make_axes_area_auto_adjustable, SubplotDivider)
2121
from mpl_toolkits.axes_grid1.axes_rgb import RGBAxes
2222
from mpl_toolkits.axes_grid1.inset_locator import (
2323
zoomed_inset_axes, mark_inset, inset_axes, BboxConnectorPatch)
@@ -367,6 +367,40 @@ def test_axes_locatable_position():
367367
0.03621495327102808)
368368

369369

370+
@image_comparison(['image_grid_each_left_label_mode_all.png'], style='mpl20',
371+
savefig_kwarg={'bbox_inches': 'tight'})
372+
def test_image_grid_each_left_label_mode_all():
373+
imdata = np.arange(100).reshape((10, 10))
374+
375+
fig = plt.figure(1, (3, 3))
376+
grid = ImageGrid(fig, (1, 1, 1), nrows_ncols=(3, 2), axes_pad=(0.5, 0.3),
377+
cbar_mode="each", cbar_location="left", cbar_size="15%",
378+
label_mode="all")
379+
# 3-tuple rect => SubplotDivider
380+
assert isinstance(grid.get_divider(), SubplotDivider)
381+
assert grid.get_axes_pad() == (0.5, 0.3)
382+
assert grid.get_aspect() # True by default for ImageGrid
383+
for ax, cax in zip(grid, grid.cbar_axes):
384+
im = ax.imshow(imdata, interpolation='none')
385+
cax.colorbar(im)
386+
387+
388+
@image_comparison(['image_grid_single_bottom_label_mode_1.png'], style='mpl20',
389+
savefig_kwarg={'bbox_inches': 'tight'})
390+
def test_image_grid_single_bottom():
391+
imdata = np.arange(100).reshape((10, 10))
392+
393+
fig = plt.figure(1, (2.5, 1.5))
394+
grid = ImageGrid(fig, (0, 0, 1, 1), nrows_ncols=(1, 3),
395+
axes_pad=(0.2, 0.15), cbar_mode="single",
396+
cbar_location="bottom", cbar_size="10%", label_mode="1")
397+
# 4-tuple rect => Divider, isinstance will give True for SubplotDivider
398+
assert type(grid.get_divider()) is Divider
399+
for i in range(3):
400+
im = grid[i].imshow(imdata, interpolation='none')
401+
grid.cbar_axes[0].colorbar(im)
402+
403+
370404
@image_comparison(['image_grid.png'],
371405
remove_text=True, style='mpl20',
372406
savefig_kwarg={'bbox_inches': 'tight'})

0 commit comments

Comments
 (0)