.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_3d.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_3d.py: 3D Plotting =========== Demonstrate the three 3-D geometry types supported by :meth:`~anyplotlib.figure_plots.Axes.plot_surface`, :meth:`~anyplotlib.figure_plots.Axes.scatter3d`, and :meth:`~anyplotlib.figure_plots.Axes.plot3d`. Drag to rotate, scroll to zoom, press **R** to reset the view. .. GENERATED FROM PYTHON SOURCE LINES 11-27 .. code-block:: Python import numpy as np import anyplotlib as vw # ── Surface ─────────────────────────────────────────────────────────────────── x = np.linspace(-3, 3, 60) y = np.linspace(-3, 3, 60) XX, YY = np.meshgrid(x, y) ZZ = np.sin(np.sqrt(XX ** 2 + YY ** 2)) fig, ax = vw.subplots(1, 1, figsize=(520, 480)) surf = ax.plot_surface(XX, YY, ZZ, colormap="viridis", x_label="x", y_label="y", z_label="sin(r)") fig .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 28-30 Scatter plot ------------ .. GENERATED FROM PYTHON SOURCE LINES 30-47 .. code-block:: Python rng = np.random.default_rng(1) n = 300 theta = rng.uniform(0, 2 * np.pi, n) phi = rng.uniform(0, np.pi, n) r = rng.uniform(0.6, 1.0, n) xs = r * np.sin(phi) * np.cos(theta) ys = r * np.sin(phi) * np.sin(theta) zs = r * np.cos(phi) fig2, ax2 = vw.subplots(1, 1, figsize=(480, 480)) sc = ax2.scatter3d(xs, ys, zs, color="#4fc3f7", point_size=3, x_label="x", y_label="y", z_label="z") fig2 .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 48-50 3-D line — parametric helix ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 50-63 .. code-block:: Python t = np.linspace(0, 4 * np.pi, 300) hx = np.cos(t) hy = np.sin(t) hz = t / (4 * np.pi) fig3, ax3 = vw.subplots(1, 1, figsize=(480, 480)) ln = ax3.plot3d(hx, hy, hz, color="#ff7043", linewidth=2, x_label="cos t", y_label="sin t", z_label="t") fig3 .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 64-68 Update the surface data live ---------------------------- Call :meth:`~anyplotlib.figure_plots.Plot3D.update` to replace the geometry without recreating the panel. .. GENERATED FROM PYTHON SOURCE LINES 68-75 .. code-block:: Python ZZ2 = np.cos(np.sqrt(XX ** 2 + YY ** 2)) surf.update(XX, YY, ZZ2) surf.set_colormap("plasma") surf.set_view(azimuth=30, elevation=40) fig .. raw:: html
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.469 seconds) .. _sphx_glr_download_auto_examples_plot_3d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_3d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_3d.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_3d.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_