不幸的是,plotly 还不支持多列图例。
一种解决方法是使用注释。考虑,
import plotly.plotly as py
from plotly.graph_objs import *
import numpy as np
import matplotlib.cm as cm
N = 10
colors=['rgba(%f,%f,%f,%f)' % tuple(c) for c in cm.rainbow((np.linspace(0,1,N)),bytes=True)]
data = []
annotations = []
lab = 'Long<br>Multiline<br>string<br>describing %s'
for i in range(0, N):
x = np.linspace(0, np.random.uniform(5, 10), 10)
y = np.linspace(1, np.random.uniform(0, 1), 10)
label = lab % i
d = Scatter(
x=x,y=y,
mode='lines',
name=label,text=(label,)*len(x),
xaxis='x1',yaxis='y1',
line=Line( color=colors[i]) )
data.append(d)
a = Annotation(
text=label,
font=Font( color=colors[i] ),
x=i, y=1,
xref='page', yref='page'
)
annotations.append(a)
layout = Layout(
showlegend=False,
annotations=annotations
)
py.plot({'data': data, 'layout': layout}, filename='multi-column-legend')
这产生https://plot.ly/~etpinard/2192/ https://plot.ly/~etpinard/2192/