.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_animation_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_animation_example.py: Animation Example =================================== Example of how to make an animation. .. image:: ../examples/example_plots/animation_example.gif :alt: GIF of a normal distribution with increasing sample size .. GENERATED FROM PYTHON SOURCE LINES 13-15 Import packages ----------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 15-23 .. code-block:: Python from gerg_plotting import Data from gerg_plotting import Histogram, Animator import cmocean import numpy as np import matplotlib.pyplot as plt from pathlib import Path .. GENERATED FROM PYTHON SOURCE LINES 25-27 Let's make some example data ----------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 27-48 .. code-block:: Python n_points = 10000 data = Data(temperature=np.random.normal(28,size=n_points)) # Let's create a histogram function to plot the data how we would like def make_hists(sample,color): '''Plot Histogram based on sample size and color''' data_sample = data[:10*sample+1] # Slice data hist = Histogram(data_sample) # Init histogram plotter hist.plot('temperature',color=color,bins=30,range=(25,31)) # Plot 1-d histogram hist.ax.set_ybound(upper=80) # Set the ybounds maximum to 80 for a clearer plot return hist.fig samples = np.arange(90) cmap = plt.get_cmap('Greens') cmap = cmocean.tools.crop_by_percent(cmap,30,which='both') colors = [cmap((idx*2)+10) for idx in samples] gif_filename = Path('example_plots/animation_example.gif') Animator().animate(plotting_function=make_hists,param_dict={'sample':samples,'color':colors},fps=12,gif_filename=gif_filename) .. rst-class:: sphx-glr-script-out .. code-block:: none Saving figures to memory, n_iterations: 90 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 23.305 seconds) .. _sphx_glr_download_auto_examples_plot_animation_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_animation_example.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_animation_example.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_animation_example.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_