Skip to content

Commit 7603999

Browse files
committed
Improve docstring and add comments
1 parent 334cc61 commit 7603999

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,21 +926,27 @@ def test_span_selector_animated_artists_callback():
926926
(ln,) = ax.plot(x, values, animated=True)
927927
(ln2, ) = ax.plot([], animated=True)
928928

929+
# spin the event loop to let the backend process any pending operations
930+
# before drawing artists
931+
# See blitting tutorial
929932
plt.pause(0.1)
930933
ax.draw_artist(ln)
931934
fig.canvas.blit(fig.bbox)
932935

933936
def mean(vmin, vmax):
937+
# Return mean of values in x between *vmin* and *vmax*
934938
indmin, indmax = np.searchsorted(x, (vmin, vmax))
935939
v = values[indmin:indmax].mean()
936-
print('here', x, v)
937940
ln2.set_data(x, v)
938941

939942
span = widgets.SpanSelector(ax, mean, direction='horizontal',
940943
onmove_callback=mean,
941944
interactive=True,
942945
drag_from_anywhere=True,
943946
useblit=True)
947+
948+
# Add span selector and check that the line is draw after it was updated
949+
# by the callback
944950
press_data = [1, 2]
945951
move_data = [2, 2]
946952
do_event(span, 'press', xdata=press_data[0], ydata=press_data[1], button=1)
@@ -952,6 +958,8 @@ def mean(vmin, vmax):
952958
span.update()
953959
assert ln2.stale is False
954960

961+
# Change span selector and check that the line is drawn/updated after its
962+
# value was updated by the callback
955963
press_data = [4, 2]
956964
move_data = [5, 2]
957965
release_data = [5, 2]

lib/matplotlib/widgets.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,12 +1841,15 @@ def set_active(self, active):
18411841

18421842
def _get_animated_artists(self):
18431843
"""
1844-
Convenience method to get all animated artists of a figure, except
1845-
those already present in self.artists. 'z_order' is ignored.
1846-
"""
1847-
return tuple([a for ax_ in self.ax.get_figure().get_axes()
1848-
for a in ax_.get_children()
1849-
if a.get_animated() and a not in self.artists])
1844+
Convenience method to get all animated artists of the figure containing
1845+
this widget, excluding those already present in self.artists.
1846+
The returned tuple is not sorted by 'z_order': z_order sorting is
1847+
valid only when considering all artists and not only a subset of all
1848+
artists.
1849+
"""
1850+
return tuple(a for ax_ in self.ax.get_figure().get_axes()
1851+
for a in ax_.get_children()
1852+
if a.get_animated() and a not in self.artists)
18501853

18511854
def update_background(self, event):
18521855
"""Force an update of the background."""

0 commit comments

Comments
 (0)