Skip to content

Commit dcc2894

Browse files
authored
allow subfigure formatting (#167)
* Allow subfigure formatting
1 parent afeaf41 commit dcc2894

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

ultraplot/figure.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,14 +1684,19 @@ def format(
16841684
for cls, sig in paxes.Axes._format_signatures.items()
16851685
}
16861686
classes = set() # track used dictionaries
1687-
for ax in axs:
1687+
for number, ax in enumerate(axs):
1688+
number = number + 1 # number from 1
1689+
store_old_number = ax.number
1690+
if ax.number != number:
1691+
ax.number = number
16881692
kw = {
16891693
key: value
16901694
for cls, kw in kws.items()
16911695
for key, value in kw.items()
16921696
if isinstance(ax, cls) and not classes.add(cls)
16931697
}
16941698
ax.format(rc_kw=rc_kw, rc_mode=rc_mode, skip_figure=True, **kw, **kwargs)
1699+
ax.number = store_old_number
16951700

16961701
# Warn unused keyword argument(s)
16971702
kw = {

ultraplot/tests/test_axes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,15 @@ def test_twin_axes_3():
175175
ax.format(ylabel="%s Thing" % color, ycolor=color)
176176
axs[0].format(xlabel="xlabel")
177177
return fig
178+
179+
180+
def test_subset_format():
181+
fig, axs = uplt.subplots(nrows=1, ncols=3)
182+
axs[1:].format(title=["a", "b"]) # allowed
183+
# Subset formatting
184+
axs[1:].format(title=["c", "d", "e"]) # allowed but does not use e
185+
assert axs[-1].get_title() == "d"
186+
assert axs[0].get_title() == ""
187+
# Shorter than number of axs
188+
with pytest.raises(ValueError):
189+
axs.format(title=["a"])

0 commit comments

Comments
 (0)