剧情小提琴剧情添加轨迹无法添加名称

时间:2019-11-17 09:35:51

标签: python plotly violin-plot

网站上的示例代码:

MessageTransfer.NonTransparentFraming

enter image description here

如果我将name ='Sample'添加到:

import plotly.graph_objects as go
from plotly.colors import n_colors
import numpy as np
np.random.seed(1)

# 12 sets of normal distributed random data, with increasing mean and standard deviation
data = (np.linspace(1, 2, 12)[:, np.newaxis] *random.randn(12, 200) + 
    (np.arange(12) + 2 * np.random.random(12))[:, np.newaxis])

colors = n_colors('rgb(5, 200, 200)', 'rgb(200, 10, 10)', 12, colortype='rgb')

fig = go.Figure()
for data_line, color in zip(data, colors):
    fig.add_trace(go.Violin(x=data_line, line_color=color))

fig.update_traces(orientation='h', side='positive', width=3, points=False)
fig.update_layout(xaxis_showgrid=False, xaxis_zeroline=False)
fig.show()

图表变化很大,毫无意义。如何为跟踪添加名称,以使它们不再读取“跟踪0”,“跟踪1”等??

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以使用name的{​​{1}}参数。 但是名称应该不同。这是修改后的示例(作为示例,我将其设置为跟踪的编号):

go.Violin

enter image description here