I\'d like to be able to add a title to the legend, in the following code. However, looking at the docs, I don\'t think there is a method for this.
import plo
Just a slight addition of property name to the already proposed solution,
import plotly
import plotly.plotly as py
import plotly.graph_objs as go
plotly.offline.init_notebook_mode(connected=True)
trace0 = go.Scatter(
x=[1, 2, 3, 4, 5],
y=[1, 2, 3, 4, 5],
name="Data1")
data = [trace0]
layout = go.Layout(
legend=dict(
x=0,
y=1,
traceorder='normal',
font=dict(
family='sans-serif',
size=12,
color='#000'
),
bgcolor='#E2E2E1',
bordercolor='#FFFFFF',
borderwidth=2
),
annotations=[
dict(
x=0,
y=1.05,
xref='paper',
yref='paper',
text='Legend Title',
showarrow=False
)
])
fig = go.Figure(data=data, layout = layout)
plotly.offline.iplot(fig)
The name property helps in adding custom names to the legends defined.