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

Skip to content

Commit 0c5b792

Browse files
authored
Merge pull request #23553 from oscargus/imagegridtests
Add tests for ImageGrid
2 parents c11b52e + 38a32f1 commit 0c5b792

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
@@ -81,9 +81,11 @@ def __init__(self, fig,
8181
----------
8282
fig : `.Figure`
8383
The parent figure.
84-
rect : (float, float, float, float) or int
85-
The axes position, as a ``(left, bottom, width, height)`` tuple or
86-
as a three-digit subplot position code (e.g., "121").
84+
rect : (float, float, float, float), (int, int, int), int, or \
85+
`~.SubplotSpec`
86+
The axes position, as a ``(left, bottom, width, height)`` tuple,
87+
as a three-digit subplot position code (e.g., ``(1, 2, 1)`` or
88+
``121``), or as a `~.SubplotSpec`.
8789
nrows_ncols : (int, int)
8890
Number of rows and columns in the grid.
8991
ngrids : int or None, default: None
@@ -139,7 +141,7 @@ def __init__(self, fig,
139141
axes_class = functools.partial(cls, **kwargs)
140142

141143
kw = dict(horizontal=[], vertical=[], aspect=aspect)
142-
if isinstance(rect, (str, Number, SubplotSpec)):
144+
if isinstance(rect, (Number, SubplotSpec)):
143145
self._divider = SubplotDivider(fig, rect, **kw)
144146
elif len(rect) == 3:
145147
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
@@ -18,7 +18,7 @@
1818
from mpl_toolkits.axes_grid1.anchored_artists import (
1919
AnchoredSizeBar, AnchoredDirectionArrows)
2020
from mpl_toolkits.axes_grid1.axes_divider import (
21-
Divider, HBoxDivider, make_axes_area_auto_adjustable)
21+
Divider, HBoxDivider, make_axes_area_auto_adjustable, SubplotDivider)
2222
from mpl_toolkits.axes_grid1.axes_rgb import RGBAxes
2323
from mpl_toolkits.axes_grid1.inset_locator import (
2424
zoomed_inset_axes, mark_inset, inset_axes, BboxConnectorPatch,
@@ -369,6 +369,40 @@ def test_axes_locatable_position():
369369
0.03621495327102808)
370370

371371

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

0 commit comments

Comments
 (0)