Skip to content

Commit 3e0902c

Browse files
committed
add api change docs
1 parent a25c1bd commit 3e0902c

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Subfigures
2+
~~~~~~~~~~
3+
4+
`.Figure.subfigures` are now added in row-major order to be consistent with
5+
`.Figure.subplots`. The return value of `~.Figure.subfigures` is not changed,
6+
but the order of ``fig.subfigs`` is.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Subfigures are now added in row-major order
2+
-------------------------------------------
3+
4+
``Figure.subfigures`` are now added in row-major order for API consistency.
5+
6+
7+
.. plot::
8+
:include-source: true
9+
:alt: Example of creating 3 by 3 subfigures.
10+
11+
import matplotlib.pyplot as plt
12+
13+
fig = plt.figure()
14+
subfigs = fig.subfigures(3, 3)
15+
x = np.linspace(0, 10, 100)
16+
17+
for i, sf in enumerate(fig.subfigs):
18+
ax = sf.subplots()
19+
ax.plot(x, np.sin(x + i), label=f'Subfigure {i+1}')
20+
sf.suptitle(f'Subfigure {i+1}')
21+
ax.set_xticks([])
22+
ax.set_yticks([])
23+
plt.show()

lib/matplotlib/figure.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,9 @@ def subfigures(self, nrows=1, ncols=1, squeeze=True,
15501550
.. note::
15511551
The *subfigure* concept is new in v3.4, and the API is still provisional.
15521552
1553+
.. versionchanged:: 3.10
1554+
subfigures are now added in row-major order.
1555+
15531556
Parameters
15541557
----------
15551558
nrows, ncols : int, default: 1

lib/matplotlib/tests/test_figure.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,12 +1735,9 @@ def test_warn_colorbar_mismatch():
17351735
subfig3_1.colorbar(im4_1)
17361736

17371737

1738-
@check_figures_equal(extensions=['png'])
1739-
def test_subfigure_row_order(fig_test, fig_ref):
1740-
# Test that subfigures are drawn in row major order.
1741-
sf_arr_ref = fig_ref.subfigures(4, 3)
1742-
for i, sf in enumerate(sf_arr_ref.ravel()):
1743-
sf.suptitle(i)
1744-
fig_test.subfigures(4, 3)
1745-
for i, sf in enumerate(fig_test.subfigs):
1746-
sf.suptitle(i)
1738+
def test_subfigure_row_order():
1739+
# Test that subfigures are drawn in row-major order.
1740+
fig = plt.figure()
1741+
sf_arr = fig.subfigures(4, 3)
1742+
for a, b in zip(sf_arr.ravel(), fig.subfigs):
1743+
assert a is b

0 commit comments

Comments
 (0)