Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Interactive demo — Plotly in the browser

A minimal runnable contribution. The chart below ships with its output already rendered, so it shows up immediately.

To run or modify this notebook against the real lab environment, use the button below. It opens JupyterLab on the lab JupyterHub (authentication required), pulls this notebook into your own container via nbgitpuller, and opens it directly — you pick the simulator (autoscaling or scheduling) at launch.

Launch on JupyterHub

# Make plotly available in the in-browser (JupyterLite) kernel.
# In a normal kernel plotly is already installed, so the guard does nothing.
try:
    import plotly  # noqa: F401
except ImportError:
    import piplite
    await piplite.install("plotly")
    await piplite.install("nbformat")
import numpy as np
import plotly.graph_objects as go

x = np.linspace(0, 10, 200)
y = np.sin(x)

fig = go.Figure(go.Scatter(x=x, y=y, mode="lines", name="sin(x)"))
fig.update_layout(
    title="Hello, Plotly",
    template="plotly_white",
    xaxis_title="x",
    yaxis_title="sin(x)",
)
fig
Loading...