8000 Handle direction="column" in axes_grid.Grid by rgbmrc · Pull Request #20373 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Handle direction="column" in axes_grid.Grid #20373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/mpl_toolkits/axes_grid1/axes_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def __init__(self, fig,
If not None, only the first *ngrids* axes in the grid are created.
direction : {"row", "column"}, default: "row"
Whether axes are created in row-major ("row by row") or
column-major order ("column by column").
column-major order ("column by column"). This also affects the
order in which axes are accessed using indexing (``grid[index]``).
axes_pad : float or (float, float), default: 0.02
Padding or (horizontal padding, vertical padding) between axes, in
inches.
Expand Down Expand Up @@ -166,7 +167,8 @@ def __init__(self, fig,
sharey = axes_array[row, 0] if share_y else None
axes_array[row, col] = axes_class(
fig, rect, sharex=sharex, sharey=sharey)
self.axes_all = axes_array.ravel().tolist()
self.axes_all = axes_array.ravel(
order="C" if self._direction == "row" else "F").tolist()
self.axes_column = axes_array.T.tolist()
self.axes_row = axes_array.tolist()
self.axes_llc = self.axes_column[0][-1]
Expand Down
24 changes: 23 additions & 1 deletion lib/mpl_toolkits/tests/test_axes_grid1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
image_comparison, remove_ticks_and_titles)

from mpl_toolkits.axes_grid1 import (
axes_size as Size, host_subplot, make_axes_locatable, AxesGrid, ImageGrid)
axes_size as Size, host_subplot, make_axes_locatable, Grid, AxesGrid, ImageGrid)
from mpl_toolkits.axes_grid1.anchored_artists import (
AnchoredSizeBar, AnchoredDirectionArrows)
from mpl_toolkits.axes_grid1.axes_divider import HBoxDivider
Expand Down Expand Up @@ -470,3 +470,25 @@ def test_axes_class_tuple():
fig = plt.figure()
axes_class = (mpl_toolkits.axes_grid1.mpl_axes.Axes, {})
gr = AxesGrid(fig, 111, nrows_ncols=(1, 1), axes_class=axes_class)


def test_grid_axes_lists():
"""Test Grid axes_all, axes_row and axes_column relationship."""
fig = plt.figure()
grid = Grid(fig, 111, (2, 3), direction="row")
assert_array_equal(grid, grid.axes_all)
assert_array_equal(grid.axes_row, np.transpose(grid.axes_column))
assert_array_equal(grid, np.ravel(grid.axes_row), "row")
grid = Grid(fig, 111, (2, 3), direction="column")
assert_array_equal(grid, np.ravel(grid.axes_column), "column")


@pytest.mark.parametrize('direction', ('row', 'column'))
def test_grid_axes_position(direction):
"""Test positioning of the axes in Grid."""
fig = plt.figure()
grid = Grid(fig, 111, (2, 2), direction=direction)
loc = [ax.get_axes_locator() for ax in np.ravel(grid.axes_row)]
assert loc[1]._nx > loc[0]._nx and loc[2]._ny < loc[0]._ny
assert loc[0]._nx == loc[2]._nx and loc[0]._ny == loc[1]._ny
assert loc[3]._nx == loc[1]._nx and loc[3]._ny == loc[2]._ny
0