Ok, I see what you mean. Yeah, it doesn’t look like you can keep plotly from overriding the legend location if the string gets too wide.
One idea would be for you to wrap the legend text across multiple lines if it’s longer that a certain width. The textwrap
module is really nice for this.
Something like:
import plotly.graph_objs as go
trace_name = 'The quick brows fox jumps over the lazy log'
legend_str = '<br>'.join(textwrap.wrap(trace_name, width=26))
figure={
'data': [
{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'scatter', 'name': 'SF'},
{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'scatter', 'name': legend_str},
],
'layout': {
'title': 'Dash Data Visualization',
'width': 600,
'height': 600
}
}