diff --git a/.circleci/config.yml b/.circleci/config.yml index e471b8d8be53..87388469caba 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/doc/Makefile b/doc/Makefile index 951eedc70f52..bc0c99e417ad 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -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 diff --git a/doc/_static/mpl.css b/doc/_static/mpl.css index ea03ce38be48..135f6fc52630 100644 --- a/doc/_static/mpl.css +++ b/doc/_static/mpl.css @@ -189,10 +189,6 @@ div.documentwrapper { } */ -div.clearer { - clear: both; -} - div.related h3 { display: none; } diff --git a/doc/_templates/autosummary.rst b/doc/_templates/autosummary.rst index 69a840b8af29..bf318f1d9aff 100644 --- a/doc/_templates/autosummary.rst +++ b/doc/_templates/autosummary.rst @@ -21,11 +21,8 @@ creates no example file for those (sphinx-gallery/sphinx-gallery#365) {% else %} -.. include:: {{module}}.{{objname}}.examples - -.. raw:: html - -
+.. minigallery:: {{module}}.{{objname}} + :add-heading: {% endif %} {% endif %} diff --git a/doc/_templates/function.rst b/doc/_templates/function.rst index 4a7464080456..0b0e8480d332 100644 --- a/doc/_templates/function.rst +++ b/doc/_templates/function.rst @@ -5,8 +5,5 @@ .. autofunction:: {{ objname }} -.. include:: {{module}}.{{objname}}.examples - -.. raw:: html - -
\ No newline at end of file +.. minigallery:: {{module}}.{{objname}} + :add-heading: diff --git a/doc/api/animation_api.rst b/doc/api/animation_api.rst index 89341db8d915..9486dfe289c7 100644 --- a/doc/api/animation_api.rst +++ b/doc/api/animation_api.rst @@ -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 diff --git a/doc/conf.py b/doc/conf.py index 6ee72e51622b..5e4523212c05 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -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' diff --git a/doc/devel/documenting_mpl.rst b/doc/devel/documenting_mpl.rst index 551b25912d8a..857f6f8a350e 100644 --- a/doc/devel/documenting_mpl.rst +++ b/doc/devel/documenting_mpl.rst @@ -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 diff --git a/doc/matplotlibrc b/doc/matplotlibrc index 5c623fc6862f..c29755d45455 100644 --- a/doc/matplotlibrc +++ b/doc/matplotlibrc @@ -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 diff --git a/examples/animation/animated_histogram.py b/examples/animation/animated_histogram.py index 42d314ab380d..c8c0911ef241 100644 --- a/examples/animation/animated_histogram.py +++ b/examples/animation/animated_histogram.py @@ -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() diff --git a/examples/animation/bayes_update.py b/examples/animation/bayes_update.py index f77deea4376b..d1c43c71fa31 100644 --- a/examples/animation/bayes_update.py +++ b/examples/animation/bayes_update.py @@ -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 diff --git a/examples/animation/double_pendulum_sgskip.py b/examples/animation/double_pendulum.py similarity index 95% rename from examples/animation/double_pendulum_sgskip.py rename to examples/animation/double_pendulum.py index 1dac5e171a0a..117322013dc8 100644 --- a/examples/animation/double_pendulum_sgskip.py +++ b/examples/animation/double_pendulum.py @@ -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): @@ -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) @@ -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() diff --git a/examples/animation/dynamic_image.py b/examples/animation/dynamic_image.py index 57d193ceae26..5543da039639 100644 --- a/examples/animation/dynamic_image.py +++ b/examples/animation/dynamic_image.py @@ -9,7 +9,7 @@ import matplotlib.pyplot as plt import matplotlib.animation as animation -fig = plt.figure() +fig, ax = plt.subplots() def f(x, y): @@ -17,6 +17,7 @@ def f(x, 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 @@ -24,7 +25,9 @@ def f(x, y): 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, diff --git a/examples/animation/random_walk.py b/examples/animation/random_walk.py index 07e4707517f2..2488f98b144c 100644 --- a/examples/animation/random_walk.py +++ b/examples/animation/random_walk.py @@ -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() diff --git a/examples/animation/simple_anim.py b/examples/animation/simple_anim.py index 173886e04c52..3bb3c4d952ba 100644 --- a/examples/animation/simple_anim.py +++ b/examples/animation/simple_anim.py @@ -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. # diff --git a/examples/animation/strip_chart.py b/examples/animation/strip_chart.py index 2661e1927b97..5e3b8fea0d04 100644 --- a/examples/animation/strip_chart.py +++ b/examples/animation/strip_chart.py @@ -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) @@ -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() diff --git a/requirements/doc/doc-requirements.txt b/requirements/doc/doc-requirements.txt index 7168886419ec..df54a5bcbfc0 100644 --- a/requirements/doc/doc-requirements.txt +++ b/requirements/doc/doc-requirements.txt @@ -12,5 +12,6 @@ colorspacious ipython ipywidgets numpydoc>=0.8 -sphinx-gallery>=0.5 +sphinx-gallery>=0.7 sphinx-copybutton +scipy