Skip to content

Commit

Permalink
Changed the behavior of named_arrays.plt.subplots() to put the orig…
Browse files Browse the repository at this point in the history
…in of the subplot grid in the lower-left corner. (#82)
  • Loading branch information
byrdie authored Oct 12, 2024
1 parent 76c0c07 commit 6a053a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion named_arrays/plt.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def subplots(
A thin wrapper around :func:`matplotlib.pyplot.subplots()` which allows for
providing axis names to the rows and columns.
Unlike :func:`matplotlib.pyplot.subplots()`,
this function arranges the subplot grid with the origin in the lower-left
corner as opposed to the upper-left corner.
Parameters
----------
axis_rows
Expand Down Expand Up @@ -94,7 +98,12 @@ def subplots(
**kwargs,
)

return fig, na.ScalarArray(axs, axes=tuple(shape.keys()))
axs = na.ScalarArray(axs, axes=tuple(shape.keys()))

if axis_rows in shape:
axs = axs[{axis_rows: slice(None, None, -1)}]

return fig, axs


def plot(
Expand Down
2 changes: 1 addition & 1 deletion named_arrays/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ def test_interp(
argvalues=[
np._NoValue,
plt.subplots()[1],
na.plt.subplots(axis_cols="x", ncols=num_x)[1],
na.plt.subplots(axis_rows="x", nrows=num_x)[1],
]
)
class TestPltPlotLikeFunctions(abc.ABC):
Expand Down

0 comments on commit 6a053a9

Please sign in to comment.