Skip to content

Commit 143cb9a

Browse files
committed
Create rectangles/lines when the other is accessed
The rectangles/lines attributes exist for backcompat and the expectation would be that when either one of them is accessed, the other would also be set in the way the older method does. So, whenever either of the property is accessed for the first time, it also sets the other property. This way, it maintains consistency with the old API.
1 parent 0f09fa1 commit 143cb9a

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``CheckButtons``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~
3+
``CheckButtons.rectangles`` and ``CheckButtons.lines`` are deprecated. (``CheckButtons`` now draws itself using `~.Axes.scatter`.)

lib/matplotlib/tests/test_widgets.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,8 +1011,6 @@ def test_check_radio_buttons_image():
10111011
with pytest.warns(DeprecationWarning):
10121012
# Trigger old-style Rectangle check boxes
10131013
cb.rectangles
1014-
with pytest.warns(DeprecationWarning):
1015-
cb.lines
10161014

10171015

10181016
@check_figures_equal(extensions=["png"])

lib/matplotlib/widgets.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,9 @@ def rectangles(self):
11321132
self._squares.set_visible(False)
11331133
for rectangle in rectangles:
11341134
self.ax.add_patch(rectangle)
1135+
if not hasattr(self, "_lines"):
1136+
with _api.suppress_matplotlib_deprecation_warning():
1137+
_ = self.lines
11351138
return self._rectangles
11361139

11371140
@_api.deprecated("3.7")
@@ -1157,6 +1160,9 @@ def lines(self):
11571160
self._lines.append((l1, l2))
11581161
self.ax.add_patch(l1)
11591162
self.ax.add_patch(l2)
1163+
if not hasattr(self, "_rectangles"):
1164+
with _api.suppress_matplotlib_deprecation_warning():
1165+
_ = self.rectangles
11601166
return self._lines
11611167

11621168

0 commit comments

Comments
 (0)