{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Animate a 3D wireframe plot\n\nA very simple \"animation\" of a 3D plot. See also :doc:`rotate_axes3d_sgskip`.\n\n(This example is skipped when building the documentation gallery because it\nintentionally takes a long time to run.)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import time\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfig = plt.figure()\nax = fig.add_subplot(projection='3d')\n\n# Make the X, Y meshgrid.\nxs = np.linspace(-1, 1, 50)\nys = np.linspace(-1, 1, 50)\nX, Y = np.meshgrid(xs, ys)\n\n# Set the z axis limits, so they aren't recalculated each frame.\nax.set_zlim(-1, 1)\n\n# Begin plotting.\nwframe = None\ntstart = time.time()\nfor phi in np.linspace(0, 180. / np.pi, 100):\n # If a line collection is already remove it before drawing.\n if wframe:\n wframe.remove()\n # Generate data.\n Z = np.cos(2 * np.pi * X + phi) * (1 - np.hypot(X, Y))\n # Plot the new wireframe and pause briefly before continuing.\n wframe = ax.plot_wireframe(X, Y, Z, rstride=2, cstride=2)\n plt.pause(.001)\n\nprint('Average FPS: %f' % (100 / (time.time() - tstart)))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. tags::\n plot-type: 3D,\n component: animation,\n level: beginner\n\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.2" } }, "nbformat": 4, "nbformat_minor": 0 }