Avoid legend automatically repositioning

Hi @maxwell8888,

Try setting the layout.legend.x property to 1.02.

            figure={
                'data': [
                    {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'scatter', 'name': 'SFABCDEFGHIJKLMNOPQRSTUVWXYZ'},
                    {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'scatter', 'name': u'Montréal'},
                ],
                'layout': {
                    'title': 'Dash Data Visualization',
                    'legend': {'x': 1.02},
                }
            }

This will cause the left edge of the legend to always start just to the right of the end of the xaxis, thus keeping the legend out of the plotting area.

BTW: There is no trace type named line, what you want here is scatter. It just so happens that scatter is what Plotly.js defaults to if it doesn’t understand the trace type.

Hope that helps!
-Jon

1 Like