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

Skip to content

Commit 31655dc

Browse files
authored
Merge pull request #27867 from timhoffm/doc-3d-anim
DOC: Update some animation related topics
2 parents c1a55a4 + db25226 commit 31655dc

File tree

3 files changed

+41
-22
lines changed

3 files changed

+41
-22
lines changed

galleries/examples/animation/random_walk.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ def random_walk(num_steps, max_step=0.05):
2525

2626
def update_lines(num, walks, lines):
2727
for line, walk in zip(lines, walks):
28-
# NOTE: there is no .set_data() for 3 dim data...
29-
line.set_data(walk[:num, :2].T)
30-
line.set_3d_properties(walk[:num, 2])
28+
line.set_data_3d(walk[:num, :].T)
3129
return lines
3230

3331

galleries/users_explain/animations/animations.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,33 @@
4949
# *func* that modifies the data plotted on the figure. It uses the *frames*
5050
# parameter to determine the length of the animation. The *interval* parameter
5151
# is used to determine time in milliseconds between drawing of two frames.
52-
# Animating using `.FuncAnimation` would usually follow the following
53-
# structure:
54-
#
55-
# - Plot the initial figure, including all the required artists. Save all the
56-
# artists in variables so that they can be updated later on during the
57-
# animation.
58-
# - Create an animation function that updates the data in each artist to
59-
# generate the new frame at each function call.
60-
# - Create a `.FuncAnimation` object with the `.Figure` and the animation
61-
# function, along with the keyword arguments that determine the animation
62-
# properties.
63-
# - Use `.animation.Animation.save` or `.pyplot.show` to save or show the
64-
# animation.
65-
#
66-
# The update function uses the ``set_*`` function for different artists to
67-
# modify the data. The following table shows a few plotting methods, the artist
68-
# types they return and some methods that can be used to update them.
52+
# Animating using `.FuncAnimation` typically requires these steps:
53+
#
54+
# 1) Plot the initial figure as you would in a static plot. Save all the created
55+
# artists, which are returned by the plot functions, in variables so that you can
56+
# access and modify them later in the animation function.
57+
# 2) Create an animation function that updates the artists for a given frame.
58+
# Typically, this calls ``set_*`` methods of the artists.
59+
# 3) Create a `.FuncAnimation`, passing the `.Figure` and the animation function.
60+
# 4) Save or show the animation using one of the following methods:
61+
#
62+
# - `.pyplot.show` to show the animation in a window
63+
# - `.Animation.to_html5_video` to create a HTML ``<video>`` tag
64+
# - `.Animation.to_jshtml` to create HTML code with interactive JavaScript animation
65+
# controls
66+
# - `.Animation.save` to save the animation to a file
67+
#
68+
# The following table shows a few plotting methods, the artists they return and some
69+
# commonly used ``set_*`` methods that update the underlying data. While updating data
70+
# is the most common operation in animations, you can also update other aspects such as
71+
# color or text position.
6972
#
7073
# ======================================== ============================= ===========================
71-
# Plotting method Artist Set method
74+
# Plotting method Artist Data set methods
7275
# ======================================== ============================= ===========================
73-
# `.Axes.plot` `.lines.Line2D` `~.lines.Line2D.set_data`
76+
# `.Axes.plot` `.lines.Line2D` `~.Line2D.set_data`,
77+
# `~.Line2D.set_xdata`,
78+
# `~.Line2D.set_ydata`
7479
# `.Axes.scatter` `.collections.PathCollection` `~.collections.\
7580
# PathCollection.set_offsets`
7681
# `.Axes.imshow` `.image.AxesImage` ``AxesImage.set_data``
@@ -88,6 +93,7 @@
8893
# `~.Ellipse.set_center`,
8994
# `~.Ellipse.set_height`,
9095
# `~.Ellipse.set_width`
96+
# `.Axes.set_title`, `.Axes.text` `.text.Text` `~.Text.set_text`
9197
# ======================================== ============================= ===========================
9298
#
9399
# Covering the set methods for all types of artists is beyond the scope of this

lib/matplotlib/lines.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,11 @@ def set_data(self, *args):
651651
Parameters
652652
----------
653653
*args : (2, N) array or two 1D arrays
654+
655+
See Also
656+
--------
657+
set_xdata
658+
set_ydata
654659
"""
655660
if len(args) == 1:
656661
(x, y), = args
@@ -1274,6 +1279,11 @@ def set_xdata(self, x):
12741279
Parameters
12751280
----------
12761281
x : 1D array
1282+
1283+
See Also
1284+
--------
1285+
set_data
1286+
set_ydata
12771287
"""
12781288
if not np.iterable(x):
12791289
raise RuntimeError('x must be a sequence')
@@ -1288,6 +1298,11 @@ def set_ydata(self, y):
12881298
Parameters
12891299
----------
12901300
y : 1D array
1301+
1302+
See Also
1303+
--------
1304+
set_data
1305+
set_xdata
12911306
"""
12921307
if not np.iterable(y):
12931308
raise RuntimeError('y must be a sequence')

0 commit comments

Comments
 (0)