Use Plotly graph for HTML and PDF output

TL;DR

Plotly for Python will produce HTML output and it needs to be handled specifically if you want to target PDF output too.

This document shows an example of following plotly doc to save output as an image to include in PDF.

It leverages quarto conditional content feature

Two Figures

import plotly.graph_objects as go
from IPython.display import Image
import numpy as np
np.random.seed(1)

N = 100
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
sz = np.random.rand(N) * 30

fig = go.Figure()
fig.add_trace(go.Scatter(
    x=x,
    y=y,
    mode="markers",
    marker=go.scatter.Marker(
        size=sz,
        color=colors,
        opacity=0.6,
        colorscale="Viridis"
    )
))
fig.show()