I'm trying to get a formatted text as the trace name in a plotly plot, but the text comes out incomplete, as if the legend box cuts it short. The code is something like this:
trace1 = go.Scatter(x = [ 0.7686741, 0.90457 , 1.140613 , 1.395725 , 1.7772 ,
2.339876 , 3.112365 , 4.161422 , 4.194801 , 5.212864 ,
6.371596 , 7.396811 , 7.604239 , 7.969025 , 8.355268 ,
8.443485 , 8.703365 , 9.63798 , 10.97553 , 14.62577 ,
14.75691 , 19.68748 ],
y = [20, 20, 21, 22, 23, 24, 25, 26, 25, 27, 28, 28, 29, 29, 30, 30, 30,
31, 32, 35, 35, 40],
name = 'Process data',
mode = 'markers',
line_width = 2)
trace2 = go.Scatter(x = df['x'],
y = results.predict(),
mode = 'lines+markers',
name = '$y= -0.000359x^4 +0.0173x^3 -0.285x^2 +2.73x +18.4$',
hoverinfo = 'x+y',
line_width = 2,)
data = [trace1, trace2]
layout = go.Layout(template= 'simple_white',
legend = dict(font_size = 20,
x = 0.02),
width = 1060, height = 550)
fig = go.Figure(data=data, layout=layout)
fig.show()
This generates the following plot:
If I set a font size > 14, the polynomial is cut by the legend box as you can see. I do need the big font size. Is there a different way to get the formatted trace name in the legend with a big font size without being cut?
Edit: removed the OLS results object, replaced x and y data and defined directly the tracename provoking the issue.





