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

Skip to content

Commit eb27af0

Browse files
authored
Merge pull request #17477 from larsoner/anim
DOC: Use Sphinx-gallery animation capture
2 parents d03c337 + de0fb17 commit eb27af0

17 files changed

+36
-31
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ apt-run: &apt-install
2727
graphviz \
2828
fonts-crosextra-carlito \
2929
fonts-freefont-otf \
30-
fonts-humor-sans
30+
fonts-humor-sans \
31+
optipng
3132
3233
fonts-run: &fonts-install
3334
name: Install custom fonts

doc/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ clean:
2424
rm -rf "$(SOURCEDIR)/savefig"
2525
rm -rf "$(SOURCEDIR)/sphinxext/__pycache__"
2626

27+
show:
28+
@python -c "import webbrowser; webbrowser.open_new_tab('file://$(shell pwd)/build/html/index.html')"
29+
2730
# Catch-all target: route all unknown targets to Sphinx using the new
2831
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
2932
%: Makefile

doc/_static/mpl.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,6 @@ div.documentwrapper {
189189
}
190190
*/
191191

192-
div.clearer {
193-
clear: both;
194-
}
195-
196192
div.related h3 {
197193
display: none;
198194
}

doc/_templates/autosummary.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@
2121
creates no example file for those (sphinx-gallery/sphinx-gallery#365)
2222
2323
{% else %}
24-
.. include:: {{module}}.{{objname}}.examples
25-
26-
.. raw:: html
27-
28-
<div class="clearer"></div>
24+
.. minigallery:: {{module}}.{{objname}}
25+
:add-heading:
2926

3027
{% endif %}
3128
{% endif %}

doc/_templates/function.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,5 @@
55

66
.. autofunction:: {{ objname }}
77

8-
.. include:: {{module}}.{{objname}}.examples
9-
10-
.. raw:: html
11-
12-
<div class="clearer"></div>
8+
.. minigallery:: {{module}}.{{objname}}
9+
:add-heading:

doc/api/animation_api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Examples
135135

136136
../gallery/animation/animate_decay
137137
../gallery/animation/bayes_update
138-
../gallery/animation/double_pendulum_sgskip
138+
../gallery/animation/double_pendulum
139139
../gallery/animation/animated_histogram
140140
../gallery/animation/rain
141141
../gallery/animation/random_walk

doc/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ def _check_dependencies():
139139
'within_subsection_order': gallery_order.subsectionorder,
140140
'remove_config_comments': True,
141141
'min_reported_time': 1,
142+
'compress_images': ('thumbnails', 'images'),
143+
'matplotlib_animations': True,
142144
}
143145

144146
plot_gallery = 'True'

doc/devel/documenting_mpl.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,9 @@ Miscellaneous
890890
Adding animations
891891
-----------------
892892

893-
There is a Matplotlib Google/Gmail account with username ``mplgithub``
893+
Animations are scraped automatically by Sphinx-gallery. If this is not
894+
desired,
895+
there is also a Matplotlib Google/Gmail account with username ``mplgithub``
894896
which was used to setup the github account but can be used for other
895897
purposes, like hosting Google docs or Youtube videos. You can embed a
896898
Matplotlib animation in the docs by first saving the animation as a

doc/matplotlibrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ backend : Agg
22
figure.figsize : 5.5, 4.5 # figure size in inches
33
savefig.dpi : 80 # figure dots per inch
44
docstring.hardcopy : True # set this when you want to generate hardcopy docstring
5+
animation.embed_limit : 30 # allow embedded animations to be big

examples/animation/animated_histogram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ def animate(i):
8787
ax.set_xlim(left[0], right[-1])
8888
ax.set_ylim(bottom.min(), top.max())
8989

90-
ani = animation.FuncAnimation(fig, animate, 100, repeat=False, blit=True)
90+
ani = animation.FuncAnimation(fig, animate, 50, repeat=False, blit=True)
9191
plt.show()

examples/animation/bayes_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, ax, prob=0.5):
3131

3232
# Set up plot parameters
3333
self.ax.set_xlim(0, 1)
34-
self.ax.set_ylim(0, 15)
34+
self.ax.set_ylim(0, 10)
3535
self.ax.grid(True)
3636

3737
# This vertical line represents the theoretical value, to

examples/animation/double_pendulum_sgskip.py renamed to examples/animation/double_pendulum.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
L2 = 1.0 # length of pendulum 2 in m
2121
M1 = 1.0 # mass of pendulum 1 in kg
2222
M2 = 1.0 # mass of pendulum 2 in kg
23+
t_stop = 5 # how many seconds to simulate
2324

2425

2526
def derivs(state, t):
@@ -48,7 +49,7 @@ def derivs(state, t):
4849

4950
# create a time array from 0..100 sampled at 0.05 second steps
5051
dt = 0.05
51-
t = np.arange(0, 20, dt)
52+
t = np.arange(0, t_stop, dt)
5253

5354
# th1 and th2 are the initial angles (degrees)
5455
# w10 and w20 are the initial angular velocities (degrees per second)
@@ -69,8 +70,8 @@ def derivs(state, t):
6970
x2 = L2*sin(y[:, 2]) + x1
7071
y2 = -L2*cos(y[:, 2]) + y1
7172

72-
fig = plt.figure()
73-
ax = fig.add_subplot(111, autoscale_on=False, xlim=(-2, 2), ylim=(-2, 2))
73+
fig = plt.figure(figsize=(5, 4))
74+
ax = fig.add_subplot(111, autoscale_on=False, xlim=(-2, 2), ylim=(-2, 1))
7475
ax.set_aspect('equal')
7576
ax.grid()
7677

examples/animation/dynamic_image.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,25 @@
99
import matplotlib.pyplot as plt
1010
import matplotlib.animation as animation
1111

12-
fig = plt.figure()
12+
fig, ax = plt.subplots()
1313

1414

1515
def f(x, y):
1616
return np.sin(x) + np.cos(y)
1717

1818
x = np.linspace(0, 2 * np.pi, 120)
1919
y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)
20+
2021
# ims is a list of lists, each row is a list of artists to draw in the
2122
# current frame; here we are just animating one artist, the image, in
2223
# each frame
2324
ims = []
2425
for i in range(60):
2526
x += np.pi / 15.
2627
y += np.pi / 20.
27-
im = plt.imshow(f(x, y), animated=True)
28+
im = ax.imshow(f(x, y), animated=True)
29+
if i == 0:
30+
ax.imshow(f(x, y)) # show an initial one first
2831
ims.append([im])
2932

3033
ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,

examples/animation/random_walk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ def update_lines(num, data_lines, lines):
6969

7070
# Creating the Animation object
7171
line_ani = animation.FuncAnimation(
72-
fig, update_lines, 25, fargs=(data, lines), interval=50)
72+
fig, update_lines, 50, fargs=(data, lines), interval=50)
7373

7474
plt.show()

examples/animation/simple_anim.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717

1818
def animate(i):
19-
line.set_ydata(np.sin(x + i / 100)) # update the data.
19+
line.set_ydata(np.sin(x + i / 50)) # update the data.
2020
return line,
2121

2222

2323
ani = animation.FuncAnimation(
24-
fig, animate, interval=2, blit=True, save_count=50)
24+
fig, animate, interval=20, blit=True, save_count=50)
2525

2626
# To save the animation, use e.g.
2727
#

examples/animation/strip_chart.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def update(self, y):
3939
return self.line,
4040

4141

42-
def emitter(p=0.03):
42+
def emitter(p=0.1):
4343
"""Return a random value in [0, 1) with probability p, else 0."""
4444
while True:
4545
v = np.random.rand(1)
@@ -48,15 +48,16 @@ def emitter(p=0.03):
4848
else:
4949
yield np.random.rand(1)
5050

51+
5152
# Fixing random state for reproducibility
52-
np.random.seed(19680801)
53+
np.random.seed(19680801 // 10)
5354

5455

5556
fig, ax = plt.subplots()
5657
scope = Scope(ax)
5758

5859
# pass a generator in "emitter" to produce data for the update func
59-
ani = animation.FuncAnimation(fig, scope.update, emitter, interval=10,
60+
ani = animation.FuncAnimation(fig, scope.update, emitter, interval=50,
6061
blit=True)
6162

6263
plt.show()

requirements/doc/doc-requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ colorspacious
1212
ipython
1313
ipywidgets
1414
numpydoc>=0.8
15-
sphinx-gallery>=0.5
15+
sphinx-gallery>=0.7
1616
sphinx-copybutton
17+
scipy

0 commit comments

Comments
 (0)