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

Skip to content

DOC: Use Sphinx-gallery animation capture #17477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ apt-run: &apt-install
graphviz \
fonts-crosextra-carlito \
fonts-freefont-otf \
fonts-humor-sans
fonts-humor-sans \
optipng

fonts-run: &fonts-install
name: Install custom fonts
Expand Down
3 changes: 3 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ clean:
rm -rf "$(SOURCEDIR)/savefig"
rm -rf "$(SOURCEDIR)/sphinxext/__pycache__"

show:
@python -c "import webbrowser; webbrowser.open_new_tab('file://$(shell pwd)/build/html/index.html')"

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
Expand Down
4 changes: 0 additions & 4 deletions doc/_static/mpl.css
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,6 @@ div.documentwrapper {
}
*/

div.clearer {
clear: both;
}

div.related h3 {
display: none;
}
Expand Down
7 changes: 2 additions & 5 deletions doc/_templates/autosummary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@
creates no example file for those (sphinx-gallery/sphinx-gallery#365)

{% else %}
.. include:: {{module}}.{{objname}}.examples

.. raw:: html

<div class="clearer"></div>
.. minigallery:: {{module}}.{{objname}}
:add-heading:

{% endif %}
{% endif %}
7 changes: 2 additions & 5 deletions doc/_templates/function.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@

.. autofunction:: {{ objname }}

.. include:: {{module}}.{{objname}}.examples

.. raw:: html

<div class="clearer"></div>
.. minigallery:: {{module}}.{{objname}}
:add-heading:
2 changes: 1 addition & 1 deletion doc/api/animation_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Examples

../gallery/animation/animate_decay
../gallery/animation/bayes_update
../gallery/animation/double_pendulum_sgskip
../gallery/animation/double_pendulum
../gallery/animation/animated_histogram
../gallery/animation/rain
../gallery/animation/random_walk
Expand Down
2 changes: 2 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def _check_dependencies():
'within_subsection_order': gallery_order.subsectionorder,
'remove_config_comments': True,
'min_reported_time': 1,
'compress_images': ('thumbnails', 'images'),
'matplotlib_animations': True,
}

plot_gallery = 'True'
Expand Down
4 changes: 3 additions & 1 deletion doc/devel/documenting_mpl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,9 @@ Miscellaneous
Adding animations
-----------------

There is a Matplotlib Google/Gmail account with username ``mplgithub``
Animations are scraped automatically by Sphinx-gallery. If this is not
desired,
there is also a Matplotlib Google/Gmail account with username ``mplgithub``
which was used to setup the github account but can be used for other
purposes, like hosting Google docs or Youtube videos. You can embed a
Matplotlib animation in the docs by first saving the animation as a
Expand Down
1 change: 1 addition & 0 deletions doc/matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ backend : Agg
figure.figsize : 5.5, 4.5 # figure size in inches
savefig.dpi : 80 # figure dots per inch
docstring.hardcopy : True # set this when you want to generate hardcopy docstring
animation.embed_limit : 30 # allow embedded animations to be big
2 changes: 1 addition & 1 deletion examples/animation/animated_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ def animate(i):
ax.set_xlim(left[0], right[-1])
ax.set_ylim(bottom.min(), top.max())

ani = animation.FuncAnimation(fig, animate, 100, repeat=False, blit=True)
ani = animation.FuncAnimation(fig, animate, 50, repeat=False, blit=True)
plt.show()
2 changes: 1 addition & 1 deletion examples/animation/bayes_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, ax, prob=0.5):

# Set up plot parameters
self.ax.set_xlim(0, 1)
self.ax.set_ylim(0, 15)
self.ax.set_ylim(0, 10)
self.ax.grid(True)

# This vertical line represents the theoretical value, to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
L2 = 1.0 # length of pendulum 2 in m
M1 = 1.0 # mass of pendulum 1 in kg
M2 = 1.0 # mass of pendulum 2 in kg
t_stop = 5 # how many seconds to simulate


def derivs(state, t):
Expand Down Expand Up @@ -48,7 +49,7 @@ def derivs(state, t):

# create a time array from 0..100 sampled at 0.05 second steps
dt = 0.05
t = np.arange(0, 20, dt)
t = np.arange(0, t_stop, dt)

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

fig = plt.figure()
ax = fig.add_subplot(111, autoscale_on=False, xlim=(-2, 2), ylim=(-2, 2))
fig = plt.figure(figsize=(5, 4))
ax = fig.add_subplot(111, autoscale_on=False, xlim=(-2, 2), ylim=(-2, 1))
ax.set_aspect('equal')
ax.grid()

Expand Down
7 changes: 5 additions & 2 deletions examples/animation/dynamic_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig = plt.figure()
fig, ax = plt.subplots()


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

x = np.linspace(0, 2 * np.pi, 120)
y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)

# ims is a list of lists, each row is a list of artists to draw in the
# current frame; here we are just animating one artist, the image, in
# each frame
ims = []
for i in range(60):
x += np.pi / 15.
y += np.pi / 20.
im = plt.imshow(f(x, y), animated=True)
im = ax.imshow(f(x, y), animated=True)
if i == 0:
ax.imshow(f(x, y)) # show an initial one first
ims.append([im])

ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,
Expand Down
2 changes: 1 addition & 1 deletion examples/animation/random_walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ def update_lines(num, data_lines, lines):

# Creating the Animation object
line_ani = animation.FuncAnimation(
fig, update_lines, 25, fargs=(data, lines), interval=50)
fig, update_lines, 50, fargs=(data, lines), interval=50)

plt.show()
4 changes: 2 additions & 2 deletions examples/animation/simple_anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@


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


ani = animation.FuncAnimation(
fig, animate, interval=2, blit=True, save_count=50)
fig, animate, interval=20, blit=True, save_count=50)

# To save the animation, use e.g.
#
Expand Down
7 changes: 4 additions & 3 deletions examples/animation/strip_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def update(self, y):
return self.line,


def emitter(p=0.03):
def emitter(p=0.1):
"""Return a random value in [0, 1) with probability p, else 0."""
while True:
v = np.random.rand(1)
Expand All @@ -48,15 +48,16 @@ def emitter(p=0.03):
else:
yield np.random.rand(1)


# Fixing random state for reproducibility
np.random.seed(19680801)
np.random.seed(19680801 // 10)


fig, ax = plt.subplots()
scope = Scope(ax)

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

plt.show()
3 changes: 2 additions & 1 deletion requirements/doc/doc-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ colorspacious
ipython
ipywidgets
numpydoc>=0.8
sphinx-gallery>=0.5
sphinx-gallery>=0.7
sphinx-copybutton
scipy