{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Rotating a 3D plot\n\nA very simple animation of a rotating 3D plot about all three axes.\n\nSee :doc:`wire3d_animation` for another example of animating a 3D plot.\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 matplotlib.pyplot as plt\n\nfrom matplotlib import animation\nfrom mpl_toolkits.mplot3d import axes3d\n\nfig = plt.figure()\nax = fig.add_subplot(projection='3d')\n\n# Grab some example data and plot a basic wireframe.\nX, Y, Z = axes3d.get_test_data(0.05)\nax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)\n\n# Set the axis labels\nax.set_xlabel('x')\nax.set_ylabel('y')\nax.set_zlabel('z')\n\n\n# Rotate the axes and update\ndef animate(angle):\n    # Normalize the angle to the range [-180, 180] for display\n    angle_norm = (angle + 180) % 360 - 180\n\n    # Cycle through a full rotation of elevation, then azimuth, roll, and all\n    elev = azim = roll = 0\n    if angle <= 360:\n        elev = angle_norm\n    elif angle <= 360*2:\n        azim = angle_norm\n    elif angle <= 360*3:\n        roll = angle_norm\n    else:\n        elev = azim = roll = angle_norm\n\n    # Update the axis view and title\n    ax.view_init(elev, azim, roll)\n    ax.set_title(f'Elevation: {elev}\u00b0, Azimuth: {azim}\u00b0, Roll: {roll}\u00b0')\n\n\nani = animation.FuncAnimation(fig, animate, interval=25, frames=360*4)\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. tags::\n   plot-type: 3D,\n   component: animation,\n   level: advanced,\n   internal: high-bandwidth\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.14.7"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}