2
如何避免子图中的重复图例标签?我会在matplotlib中介绍的一种方法是将自定义图例标签传递给图例对象。我无法在剧情中找到相应选项的任何文档。有任何想法吗?如何避免重复图例标签或传递自定义图例标签
traces = []
colors = {'Iris-setosa': 'rgb(31, 119, 180)',
'Iris-versicolor': 'rgb(255, 127, 14)',
'Iris-virginica': 'rgb(44, 160, 44)'}
for col in range(4):
for key in colors:
traces.append(Histogram(x=X[y==key, col],
opacity=0.75,
xaxis='x%s' %(col+1),
marker=Marker(color=colors[key]),
name=key
)
)
data = Data(traces)
layout = Layout(barmode='overlay',
xaxis=XAxis(domain=[0, 0.25], title='sepal length (cm)'),
xaxis2=XAxis(domain=[0.3, 0.5], title='sepal width (cm)'),
xaxis3=XAxis(domain=[0.55, 0.75], title='petal length (cm)'),
xaxis4=XAxis(domain=[0.8, 1], title='petal width (cm)'),
yaxis=YAxis(title='count'),
title='Distribution of the different Iris flower features')
fig = Figure(data=data, layout=layout)
py.iplot(fig)
谢谢,完美的作品! – Sebastian 2014-11-14 23:13:34
@SebastianRaschka但是,如果'trace1'的图例被隐藏,那么您无法控制或隐藏'trace1'的痕迹。 – 2016-07-07 16:46:22