Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 273cebe

Browse files
committed
Fix toggling of MultiCursor.{horizOn,vertOn}
By implementing `_onmove` in a similar manner to `Cursor`. Followup to #19763.
1 parent 65e54af commit 273cebe

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

doc/api/next_api_changes/deprecations/19763-ES.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33

44
Access to the event handlers for the `.Cursor` and `.MultiCursor` widgets is
5-
now deprecated.
5+
now deprecated. The related *needclear* attribute is also deprecated.

lib/matplotlib/widgets.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,9 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False,
17461746
self.linev = ax.axvline(ax.get_xbound()[0], visible=False, **lineprops)
17471747

17481748
self.background = None
1749-
self.needclear = False
1749+
self._needclear = False
1750+
1751+
needclear = _api.deprecate_privatize_attribute("3.7")
17501752

17511753
@_api.deprecated('3.7')
17521754
def clear(self, event):
@@ -1776,11 +1778,11 @@ def _onmove(self, event):
17761778
self.linev.set_visible(False)
17771779
self.lineh.set_visible(False)
17781780

1779-
if self.needclear:
1781+
if self._needclear:
17801782
self.canvas.draw()
1781-
self.needclear = False
1783+
self._needclear = False
17821784
return
1783-
self.needclear = True
1785+
self._needclear = True
17841786

17851787
self.linev.set_xdata((event.xdata, event.xdata))
17861788
self.linev.set_visible(self.visible and self.vertOn)
@@ -1863,28 +1865,21 @@ def __init__(self, canvas, axes, useblit=True, horizOn=False, vertOn=True,
18631865
self.useblit = (
18641866
useblit
18651867
and all(canvas.supports_blit for canvas in self._canvas_infos))
1866-
self.needclear = False
18671868

18681869
if self.useblit:
18691870
lineprops['animated'] = True
18701871

1871-
if vertOn:
1872-
self.vlines = [ax.axvline(xmid, visible=False, **lineprops)
1873-
for ax in axes]
1874-
else:
1875-
self.vlines = []
1876-
1877-
if horizOn:
1878-
self.hlines = [ax.axhline(ymid, visible=False, **lineprops)
1879-
for ax in axes]
1880-
else:
1881-
self.hlines = []
1872+
self.vlines = [ax.axvline(xmid, visible=False, **lineprops)
1873+
for ax in axes]
1874+
self.hlines = [ax.axhline(ymid, visible=False, **lineprops)
1875+
for ax in axes]
18821876

18831877
self.connect()
18841878

18851879
canvas = _api.deprecate_privatize_attribute("3.6")
18861880
background = _api.deprecated("3.6")(lambda self: (
18871881
self._backgrounds[self.axes[0].figure.canvas] if self.axes else None))
1882+
needclear = _api.deprecated("3.7")(lambda self: False)
18881883

18891884
def connect(self):
18901885
"""Connect events."""
@@ -1925,15 +1920,12 @@ def _onmove(self, event):
19251920
or event.inaxes not in self.axes
19261921
or not event.canvas.widgetlock.available(self)):
19271922
return
1928-
self.needclear = True
1929-
if self.vertOn:
1930-
for line in self.vlines:
1931-
line.set_xdata((event.xdata, event.xdata))
1932-
line.set_visible(self.visible)
1933-
if self.horizOn:
1934-
for line in self.hlines:
1935-
line.set_ydata((event.ydata, event.ydata))
1936-
line.set_visible(self.visible)
1923+
for line in self.vlines:
1924+
line.set_xdata((event.xdata, event.xdata))
1925+
line.set_visible(self.visible and self.vertOn)
1926+
for line in self.hlines:
1927+
line.set_ydata((event.ydata, event.ydata))
1928+
line.set_visible(self.visible and self.horizOn)
19371929
if self.visible and (self.vertOn or self.horizOn):
19381930
self._update()
19391931

0 commit comments

Comments
 (0)