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