Skip to content

Commit 4848787

Browse files
authored
Merge pull request #16049 from anntzer/subplotspecrepr
Add __repr__ to SubplotSpec.
2 parents 4286537 + e03a2f9 commit 4848787

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/matplotlib/gridspec.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,11 @@ def __init__(self, gridspec, num1, num2=None):
522522
else:
523523
self._layoutbox = None
524524

525+
def __repr__(self):
526+
return (f"{self.get_gridspec()}["
527+
f"{self.rowspan.start}:{self.rowspan.stop}, "
528+
f"{self.colspan.start}:{self.colspan.stop}]")
529+
525530
@staticmethod
526531
def _from_subplot_args(figure, args):
527532
"""

lib/matplotlib/tests/test_gridspec.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ def test_height_ratios():
2424
"""
2525
with pytest.raises(ValueError):
2626
gridspec.GridSpec(1, 1, height_ratios=[2, 1, 3])
27+
28+
29+
def test_repr():
30+
ss = gridspec.GridSpec(3, 3)[2, 1:3]
31+
assert repr(ss) == "GridSpec(3, 3)[2:3, 1:3]"

0 commit comments

Comments
 (0)