I'm attempting to create an annotation that consists of a fit equation and optimal parameters. I've used a string label that was also used to generate a similar output using matplotlib
. The label has mathematical symbols/notation.
A minimum example:
import plotly.graph_objects as go
# make up some points
xpts = [0, 1, 2, 3, 4]
ypts = [0, 2, 4, 6, 8]
# the annotation to display
func_label = "".join(["$f(x) = mx + b$\n",
f"$m = 2.0$ \n",
f"$b = 0.0$\n",
f"$R^2 = 0.99$\n",
f"$RMSE = 0.01$",])
fig = go.Figure(
data=[go.Scatter(x=xpts,
y=ypts,
mode='markers',
name="Data"
),
],
layout=go.Layout(title="Plot Title",
xaxis_title="X-axis",
yaxis_title="Y-axis")
)
# add the annotation
fig.add_annotation(x=0.25, y=6, text="<br>".join(func_label.split('\n')), showarrow=False)
fig.show(renderer="browser")
The resulting plot output only shows the first line of the annotation:
It seems like the $
may be causing an issue, as when I remove them it prints all lines. Is there a way to do this while preserving the math rendering?