3D plots with Plotly

3D plots with Plotly#

This TR tests whether the HTML build of the TR notebooks supports Plotly figures. It’s a follow-up to TR-006, without the interactivity of ipywidgets, but with the better 3D rendering of Plotly. For more info on how Plotly figures can be embedded in Sphinx HTML builds, see this page of MyST-NB (particularly the remark on html_js_files.

The following example is copied from this tutorial.

import numpy as np
import plotly.graph_objects as go

X, Y, Z = np.mgrid[-5:5:40j, -5:5:40j, -5:5:40j]
ellipsoid = X * X * 0.5 + Y * Y + Z * Z * 2
fig = go.Figure(
    data=go.Isosurface(
        x=X.flatten(),
        y=Y.flatten(),
        z=Z.flatten(),
        value=ellipsoid.flatten(),
        isomin=5,
        isomax=50,
        surface_fill=0.4,
        caps=dict(x_show=False, y_show=False),
        slices_z=dict(
            show=True,
            locations=[
                -1,
                -3,
            ],
        ),
        slices_y=dict(show=True, locations=[0]),
    )
)
fig.show()