.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/miscellanea/animate_surface.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_gallery_miscellanea_animate_surface.py: Animating a gridded surface --------------------------- This example demonstrates how to animate gridded data using `~cartopy.mpl.geoaxes.GeoAxes.pcolormesh()`. .. GENERATED FROM PYTHON SOURCE LINES 8-41 .. container:: sphx-glr-animation .. raw:: html
.. code-block:: Python from matplotlib.animation import FuncAnimation import matplotlib.pyplot as plt import numpy as np import cartopy.crs as ccrs fig = plt.figure(figsize=(10, 5)) ax = plt.axes(projection=ccrs.Robinson()) ax.set_global() ax.coastlines() x = np.linspace(-80, 80) xs, ys = np.meshgrid(2 * x + 180, x) zs = xs + ys vmin, vmax = np.min(zs), np.max(zs) mesh = ax.pcolormesh(xs, ys, np.zeros_like(zs), transform=ccrs.PlateCarree(), shading='auto', vmin=vmin, vmax=vmax) n = 10 def update_mesh(t): mesh.set_array(zs.ravel() * t) ts = [i / n for i in range(n)] # Go back to the start to make it a smooth repeat ts += ts[::-1] ani = FuncAnimation(fig, update_mesh, frames=ts, interval=100) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.607 seconds) .. _sphx_glr_download_gallery_miscellanea_animate_surface.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: animate_surface.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: animate_surface.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_