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

Skip to content

Commit ea732ef

Browse files
committed
Put onselect in __init__, fix syntax error, make sure lines are animated.
1 parent e43c788 commit ea732ef

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/matplotlib/widgets.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,7 @@ def __init__(self, ax, onselect, useblit=False, button=None):
11011101
AxesWidget.__init__(self, ax)
11021102

11031103
self.visible = True
1104+
self.onselect = onselect
11041105
self.connect_default_events()
11051106

11061107
self.background = None
@@ -1130,7 +1131,7 @@ def update_background(self, event):
11301131
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
11311132

11321133
def connect_default_events(self):
1133-
"""Connect the major canvas events to methods.""""
1134+
"""Connect the major canvas events to methods."""
11341135
self.connect_event('motion_notify_event', self._onmove)
11351136
self.connect_event('button_press_event', self._press)
11361137
self.connect_event('button_release_event', self._release)
@@ -1357,7 +1358,8 @@ def __init__(self, ax, onselect, direction, minspan=None, useblit=False,
13571358
def new_axes(self, ax):
13581359
self.ax = ax
13591360
if self.canvas is not ax.figure.canvas:
1360-
self.disconnect_events()
1361+
if not self.canvas is None:
1362+
self.disconnect_events()
13611363

13621364
self.canvas = ax.figure.canvas
13631365
self.connect_default_events()
@@ -1572,6 +1574,8 @@ def __init__(self, ax, onselect, drawtype='box',
15721574
lineprops = dict(color='black', linestyle='-',
15731575
linewidth=2, alpha=0.5)
15741576
self.lineprops = lineprops
1577+
if useblit:
1578+
self.lineprops['animated'] = True
15751579
self.to_draw = Line2D([0, 0], [0, 0], visible=False,
15761580
**self.lineprops)
15771581
self.ax.add_line(self.to_draw)
@@ -1705,6 +1709,8 @@ def __init__(self, ax, onselect=None, useblit=True, lineprops=None,
17051709

17061710
if lineprops is None:
17071711
lineprops = dict()
1712+
if useblit:
1713+
lineprops['animated'] = True
17081714
self.line = Line2D([], [], **lineprops)
17091715
self.line.set_visible(False)
17101716
self.ax.add_line(self.line)

0 commit comments

Comments
 (0)