Skip to content

Commit

Permalink
Add tests for ImageGrid
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Aug 4, 2022
1 parent 65cbdef commit 0a16124
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/mpl_toolkits/axes_grid1/axes_grid.py
Expand Up @@ -83,9 +83,10 @@ def __init__(self, fig,
----------
fig : `.Figure`
The parent figure.
rect : (float, float, float, float) or int
rect : (float, float, float, float), (int, int, int) or int
The axes position, as a ``(left, bottom, width, height)`` tuple or
as a three-digit subplot position code (e.g., "121").
as a three-digit subplot position code (e.g., ``(1, 2, 1)`` or
``121``).
nrows_ncols : (int, int)
Number of rows and columns in the grid.
ngrids : int or None, default: None
Expand Down Expand Up @@ -140,7 +141,7 @@ def __init__(self, fig,
axes_class = functools.partial(cls, **kwargs)

kw = dict(horizontal=[], vertical=[], aspect=aspect)
if isinstance(rect, (str, Number, SubplotSpec)):
if isinstance(rect, (Number, SubplotSpec)):
self._divider = SubplotDivider(fig, rect, **kw)
elif len(rect) == 3:
self._divider = SubplotDivider(fig, *rect, **kw)
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 33 additions & 1 deletion lib/mpl_toolkits/tests/test_axes_grid1.py
Expand Up @@ -17,7 +17,7 @@
from mpl_toolkits.axes_grid1.anchored_artists import (
AnchoredSizeBar, AnchoredDirectionArrows)
from mpl_toolkits.axes_grid1.axes_divider import (
HBoxDivider, make_axes_area_auto_adjustable)
Divider, HBoxDivider, make_axes_area_auto_adjustable, SubplotDivider)
from mpl_toolkits.axes_grid1.axes_rgb import RGBAxes
from mpl_toolkits.axes_grid1.inset_locator import (
zoomed_inset_axes, mark_inset, inset_axes, BboxConnectorPatch)
Expand Down Expand Up @@ -367,6 +367,38 @@ def test_axes_locatable_position():
0.03621495327102808)


@image_comparison(['image_grid_each_left.png'], style='mpl20',
savefig_kwarg={'bbox_inches': 'tight'})
def test_image_grid_each_left():
im = np.arange(100).reshape((10, 10))

fig = plt.figure(1, (3, 3))
grid = ImageGrid(fig, (1, 1, 1), nrows_ncols=(2, 2), axes_pad=(0.35, 0.3),
cbar_mode="each", cbar_location="left", cbar_size="15%",
label_mode="all")
# 3-tuple rect => SubplotDivider
assert isinstance(grid.get_divider(), SubplotDivider)
assert grid.get_axes_pad() == (0.35, 0.3)
assert grid.get_aspect() # True by default for ImageGrid
for i in range(4):
grid[i].imshow(im, interpolation='none')


@image_comparison(['image_grid_single_bottom.png'], style='mpl20',
savefig_kwarg={'bbox_inches': 'tight'})
def test_image_grid_single_bottom():
im = np.arange(100).reshape((10, 10))

fig = plt.figure(1, (2.5, 2.5))
grid = ImageGrid(fig, (0, 0, 1, 1), nrows_ncols=(2, 2),
axes_pad=(0.2, 0.15), cbar_mode="single",
cbar_location="bottom", cbar_size="10%")
# 4-tuple rect => Divider, isinstance will give True for SubplotDivider
assert type(grid.get_divider()) is Divider
for i in range(4):
grid[i].imshow(im, interpolation='none')


@image_comparison(['image_grid.png'],
remove_text=True, style='mpl20',
savefig_kwarg={'bbox_inches': 'tight'})
Expand Down

0 comments on commit 0a16124

Please sign in to comment.