I would like to split my legend text into two lines. This would help increase the width of the plot and reduce the width of the legend. However, when I use \n, it gets replaced with a space. Is there a way to split the text into two lines?
import plotly.graph_objs as go
from plotly.offline import plot
import numpy as np
x = np.arange(0, 100)
y = np.random.normal(size=100)
fig = go.Figure()
fig.add_trace(go.Scatter(
name='A very long\nlegend entry',
x=x,
y=y,
showlegend=True,
mode='lines',
line={'color': 'Black'}))
fig.update_layout(
legend={
'x': 1.01,
'y': 0.5})
plot(fig)

Trace names are interpreted as pseudo-HTML so you can use <br> instead of \n for newlines: name='A very long<br>legend entry'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With