Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3a5e624

Browse filesBrowse files
committed
Merge pull request #3985 from WeatherGod/widget_improvements
ENH : Widget and animation improvements
2 parents cda7776 + e012f78 commit 3a5e624
Copy full SHA for 3a5e624

File tree

Expand file treeCollapse file tree

2 files changed

+44
-15
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+44
-15
lines changed

‎examples/animation/animate_decay.py

Copy file name to clipboardExpand all lines: examples/animation/animate_decay.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def data_gen(t=0):
77
cnt = 0
88
while cnt < 1000:
99
cnt += 1
10-
t += 0.05
10+
t += 0.1
1111
yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)
1212

1313
fig, ax = plt.subplots()
@@ -32,6 +32,6 @@ def run(data):
3232

3333
return line,
3434

35-
ani = animation.FuncAnimation(fig, run, data_gen, blit=True, interval=10,
35+
ani = animation.FuncAnimation(fig, run, data_gen, blit=False, interval=10,
3636
repeat=False)
3737
plt.show()

‎lib/matplotlib/widgets.py

Copy file name to clipboardExpand all lines: lib/matplotlib/widgets.py
+42-13Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -569,24 +569,39 @@ def _clicked(self, event):
569569
if event.inaxes != self.ax:
570570
return
571571

572-
for p, t, lines in zip(self.rectangles, self.labels, self.lines):
572+
for i, (p, t) in enumerate(zip(self.rectangles, self.labels)):
573573
if (t.get_window_extent().contains(event.x, event.y) or
574574
p.get_window_extent().contains(event.x, event.y)):
575-
l1, l2 = lines
576-
l1.set_visible(not l1.get_visible())
577-
l2.set_visible(not l2.get_visible())
578-
thist = t
575+
self.set_active(i)
579576
break
580577
else:
581578
return
582579

580+
def set_active(self, index):
581+
"""
582+
Directly (de)activate a check button by index.
583+
584+
*index* is an index into the original label list
585+
that this object was constructed with.
586+
Raises ValueError if *index* is invalid.
587+
588+
Callbacks will be triggered if :attr:`eventson` is True.
589+
590+
"""
591+
if 0 > index >= len(self.labels):
592+
raise ValueError("Invalid CheckButton index: %d" % index)
593+
594+
l1, l2 = self.lines[index]
595+
l1.set_visible(not l1.get_visible())
596+
l2.set_visible(not l2.get_visible())
597+
583598
if self.drawon:
584599
self.ax.figure.canvas.draw()
585600

586601
if not self.eventson:
587602
return
588603
for cid, func in six.iteritems(self.observers):
589-
func(thist.get_text())
604+
func(self.labels[index].get_text())
590605

591606
def on_clicked(self, func):
592607
"""
@@ -698,17 +713,31 @@ def inside(p):
698713
pcirc = np.array([p.center[0], p.center[1]])
699714
return dist(pclicked, pcirc) < p.radius
700715

701-
for p, t in zip(self.circles, self.labels):
716+
for i, (p, t) in enumerate(zip(self.circles, self.labels)):
702717
if t.get_window_extent().contains(event.x, event.y) or inside(p):
703-
inp = p
704-
thist = t
705-
self.value_selected = t.get_text()
718+
self.set_active(i)
706719
break
707720
else:
708721
return
709722

710-
for p in self.circles:
711-
if p == inp:
723+
def set_active(self, index):
724+
"""
725+
Trigger which radio button to make active.
726+
727+
*index* is an index into the original label list
728+
that this object was constructed with.
729+
Raise ValueError if the index is invalid.
730+
731+
Callbacks will be triggered if :attr:`eventson` is True.
732+
733+
"""
734+
if 0 > index >= len(self.labels):
735+
raise ValueError("Invalid RadioButton index: %d" % index)
736+
737+
self.value_selected = self.labels[index].get_text()
738+
739+
for i, p in enumerate(self.circles):
740+
if i == index:
712741
color = self.activecolor
713742
else:
714743
color = self.ax.get_axis_bgcolor()
@@ -720,7 +749,7 @@ def inside(p):
720749
if not self.eventson:
721750
return
722751
for cid, func in six.iteritems(self.observers):
723-
func(thist.get_text())
752+
func(self.labels[index].get_text())
724753

725754
def on_clicked(self, func):
726755
"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.