@@ -1680,8 +1680,8 @@ class MultiCursor(Widget):
1680
1680
1681
1681
Parameters
1682
1682
----------
1683
- canvas : `matplotlib.backend_bases.FigureCanvasBase`
1684
- The FigureCanvas that contains all the Axes .
1683
+ canvas : object
1684
+ This parameter is entirely unused and only kept for back-compatibility .
1685
1685
1686
1686
axes : list of `matplotlib.axes.Axes`
1687
1687
The `~.axes.Axes` to attach the cursor to.
@@ -1708,21 +1708,29 @@ class MultiCursor(Widget):
1708
1708
See :doc:`/gallery/widgets/multicursor`.
1709
1709
"""
1710
1710
1711
+ @_api .make_keyword_only ("3.6" , "useblit" )
1711
1712
def __init__ (self , canvas , axes , useblit = True , horizOn = False , vertOn = True ,
1712
1713
** lineprops ):
1713
- self .canvas = canvas
1714
+ # canvas is stored only to provide the deprecated .canvas attribute;
1715
+ # once it goes away the unused argument won't need to be stored at all.
1716
+ self ._canvas = canvas
1717
+
1714
1718
self .axes = axes
1715
1719
self .horizOn = horizOn
1716
1720
self .vertOn = vertOn
1717
1721
1722
+ self ._canvas_infos = {
1723
+ ax .figure .canvas : {"cids" : [], "background" : None } for ax in axes }
1724
+
1718
1725
xmin , xmax = axes [- 1 ].get_xlim ()
1719
1726
ymin , ymax = axes [- 1 ].get_ylim ()
1720
1727
xmid = 0.5 * (xmin + xmax )
1721
1728
ymid = 0.5 * (ymin + ymax )
1722
1729
1723
1730
self .visible = True
1724
- self .useblit = useblit and self .canvas .supports_blit
1725
- self .background = None
1731
+ self .useblit = (
1732
+ useblit
1733
+ and all (canvas .supports_blit for canvas in self ._canvas_infos ))
1726
1734
self .needclear = False
1727
1735
1728
1736
if self .useblit :
@@ -1742,33 +1750,39 @@ def __init__(self, canvas, axes, useblit=True, horizOn=False, vertOn=True,
1742
1750
1743
1751
self .connect ()
1744
1752
1753
+ canvas = _api .deprecate_privatize_attribute ("3.6" )
1754
+ background = _api .deprecated ("3.6" )(lambda self : (
1755
+ self ._backgrounds [self .axes [0 ].figure .canvas ] if self .axes else None ))
1756
+
1745
1757
def connect (self ):
1746
1758
"""Connect events."""
1747
- self ._cidmotion = self .canvas .mpl_connect ('motion_notify_event' ,
1748
- self .onmove )
1749
- self ._ciddraw = self .canvas .mpl_connect ('draw_event' , self .clear )
1759
+ for canvas , info in self ._canvas_infos .items ():
1760
+ info ["cids" ] = [
1761
+ canvas .mpl_connect ('motion_notify_event' , self .onmove ),
1762
+ canvas .mpl_connect ('draw_event' , self .clear ),
1763
+ ]
1750
1764
1751
1765
def disconnect (self ):
1752
1766
"""Disconnect events."""
1753
- self .canvas .mpl_disconnect (self ._cidmotion )
1754
- self .canvas .mpl_disconnect (self ._ciddraw )
1767
+ for canvas , info in self ._canvas_infos .items ():
1768
+ for cid in info ["cids" ]:
1769
+ canvas .mpl_disconnect (cid )
1770
+ info ["cids" ].clear ()
1755
1771
1756
1772
def clear (self , event ):
1757
1773
"""Clear the cursor."""
1758
1774
if self .ignore (event ):
1759
1775
return
1760
1776
if self .useblit :
1761
- self . background = (
1762
- self . canvas .copy_from_bbox (self . canvas .figure .bbox ) )
1777
+ for canvas , info in self . _canvas_infos . items ():
1778
+ info [ "background" ] = canvas .copy_from_bbox (canvas .figure .bbox )
1763
1779
for line in self .vlines + self .hlines :
1764
1780
line .set_visible (False )
1765
1781
1766
1782
def onmove (self , event ):
1767
- if self .ignore (event ):
1768
- return
1769
- if event .inaxes not in self .axes :
1770
- return
1771
- if not self .canvas .widgetlock .available (self ):
1783
+ if (self .ignore (event )
1784
+ or event .inaxes not in self .axes
1785
+ or not event .canvas .widgetlock .available (self )):
1772
1786
return
1773
1787
self .needclear = True
1774
1788
if not self .visible :
@@ -1785,17 +1799,20 @@ def onmove(self, event):
1785
1799
1786
1800
def _update (self ):
1787
1801
if self .useblit :
1788
- if self .background is not None :
1789
- self .canvas .restore_region (self .background )
1802
+ for canvas , info in self ._canvas_infos .items ():
1803
+ if info ["background" ]:
1804
+ canvas .restore_region (info ["background" ])
1790
1805
if self .vertOn :
1791
1806
for ax , line in zip (self .axes , self .vlines ):
1792
1807
ax .draw_artist (line )
1793
1808
if self .horizOn :
1794
1809
for ax , line in zip (self .axes , self .hlines ):
1795
1810
ax .draw_artist (line )
1796
- self .canvas .blit ()
1811
+ for canvas in self ._canvas_infos :
1812
+ canvas .blit ()
1797
1813
else :
1798
- self .canvas .draw_idle ()
1814
+ for canvas in self ._canvas_infos :
1815
+ canvas .draw_idle ()
1799
1816
1800
1817
1801
1818
class _SelectorWidget (AxesWidget ):
0 commit comments