pythonplotly小提琴图显示负尾

joh*_*son 2 python boxplot plotly violin-plot plotly-python

pythonplotly小提琴图显示负尾,但没有低于0的值。实际y轴在0到23之间(24小时间隔)。但小提琴图尾部超过 23 且小于 0(第 0 和第 23 边距级别添加到图表中)。

在此输入图像描述

代码:

fig = go.Figure()

fig.add_trace(go.Violin(x=df['Region'][ df['alarm_severity'] == 'CRITICAL' ],
                        y=df['OccurredTime'][ df['alarm_severity'] == 'CRITICAL' ],
                        legendgroup='CRITICAL', scalegroup='CRITICAL', name='CRITICAL',
                        line_color='blue')
             )

fig.add_trace(go.Violin(x=df['Region'][ df['alarm_severity'] == 'MAJOR' ],
                        y=df['OccurredTime'][ df['alarm_severity'] == 'MAJOR' ],
                        legendgroup='MAJOR', scalegroup='MAJOR', name='MAJOR',
                        line_color='red')
             )
fig.add_trace(go.Violin(x=df['Region'][ df['alarm_severity'] == 'WARNING' ],
                        y=df['OccurredTime'][ df['alarm_severity'] == 'WARNING' ],
                        legendgroup='WARNING', scalegroup='WARNING', name='WARNING',
                        line_color='green')
             )


fig.add_trace(go.Violin(x=df['Region'][ df['alarm_severity'] == 'MINOR' ],
                        y=df['OccurredTime'][ df['alarm_severity'] == 'MINOR' ],
                        legendgroup='MINOR', scalegroup='MINOR', name='MINOR',
                        line_color='orange')
             )



fig.update_traces(box_visible=True, meanline_visible=True )
fig.update_layout(violinmode='group',width=1000,
    height=600)



fig.show()
Run Code Online (Sandbox Code Playgroud)

Car*_*sSR 8

如果您查看 Violin 文档(https://plotly.com/python-api-reference/ generated/plotly.graph_objects.Violin.html),您可能需要在所有 Violin 初始化中添加spanmode = \'hard\'. 这样,您的最大和最小跨度是由您的数据设置的,而不是由 Silverman\xe2\x80\x99s 经验法则(带宽)设置。

\n

spanmode \xe2\x80\x93设置计算密度函数的数据空间范围的方法。\xe2\x80\x9csoft\xe2\x80\x9d 表示跨度从样本\xe2\x80\x99s 最小值减去两个带宽到样本\xe2\x80\x99s 最大值加上两个带宽。\xe2\x80\x9chard\xe2\x80\x9d 表示跨度从样本\xe2\x80\x99s 最小值到最大值。对于自定义跨度设置,请使用模式 \xe2\x80\x9cmanual\xe2\x80\x9d 并填写跨度属性。

\n