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

Skip to content

Commit d7d50d9

Browse files
authored
Merge pull request #20373 from rgbmrc/patch-1
Handle direction="column" in axes_grid.Grid
2 parents e4670d0 + 20c6131 commit d7d50d9

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

lib/mpl_toolkits/axes_grid1/axes_grid.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def __init__(self, fig,
9898
If not None, only the first *ngrids* axes in the grid are created.
9999
direction : {"row", "column"}, default: "row"
100100
Whether axes are created in row-major ("row by row") or
101-
column-major order ("column by column").
101+
column-major order ("column by column"). This also affects the
102+
order in which axes are accessed using indexing (``grid[index]``).
102103
axes_pad : float or (float, float), default: 0.02
103104
Padding or (horizontal padding, vertical padding) between axes, in
104105
inches.
@@ -166,7 +167,8 @@ def __init__(self, fig,
166167
sharey = axes_array[row, 0] if share_y else None
167168
axes_array[row, col] = axes_class(
168169
fig, rect, sharex=sharex, sharey=sharey)
169-
self.axes_all = axes_array.ravel().tolist()
170+
self.axes_all = axes_array.ravel(
171+
order="C" if self._direction == "row" else "F").tolist()
170172
self.axes_column = axes_array.T.tolist()
171173
self.axes_row = axes_array.tolist()
172174
self.axes_llc = self.axes_column[0][-1]

lib/mpl_toolkits/tests/test_axes_grid1.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
image_comparison, remove_ticks_and_titles)
1212

1313
from mpl_toolkits.axes_grid1 import (
14-
axes_size as Size, host_subplot, make_axes_locatable, AxesGrid, ImageGrid)
14+
axes_size as Size,
15+
host_subplot, make_axes_locatable,
16+
Grid, AxesGrid, ImageGrid)
1517
from mpl_toolkits.axes_grid1.anchored_artists import (
1618
AnchoredSizeBar, AnchoredDirectionArrows)
1719
from mpl_toolkits.axes_grid1.axes_divider import HBoxDivider
@@ -470,3 +472,25 @@ def test_axes_class_tuple():
470472
fig = plt.figure()
471473
axes_class = (mpl_toolkits.axes_grid1.mpl_axes.Axes, {})
472474
gr = AxesGrid(fig, 111, nrows_ncols=(1, 1), axes_class=axes_class)
475+
476+
477+
def test_grid_axes_lists():
478+
"""Test Grid axes_all, axes_row and axes_column relationship."""
479+
fig = plt.figure()
480+
grid = Grid(fig, 111, (2, 3), direction="row")
481+
assert_array_equal(grid, grid.axes_all)
482+
assert_array_equal(grid.axes_row, np.transpose(grid.axes_column))
483+
assert_array_equal(grid, np.ravel(grid.axes_row), "row")
484+
grid = Grid(fig, 111, (2, 3), direction="column")
485+
assert_array_equal(grid, np.ravel(grid.axes_column), "column")
486+
487+
488+
@pytest.mark.parametrize('direction', ('row', 'column'))
489+
def test_grid_axes_position(direction):
490+
"""Test positioning of the axes in Grid."""
491+
fig = plt.figure()
492+
grid = Grid(fig, 111, (2, 2), direction=direction)
493+
loc = [ax.get_axes_locator() for ax in np.ravel(grid.axes_row)]
494+
assert loc[1]._nx > loc[0]._nx and loc[2]._ny < loc[0]._ny
495+
assert loc[0]._nx == loc[2]._nx and loc[0]._ny == loc[1]._ny
496+
assert loc[3]._nx == loc[1]._nx and loc[3]._ny == loc[2]._ny

0 commit comments

Comments
 (0)