python plotly violin plot shows a negative tail but there are no values below 0. actual y-axis between 0 to 23(24 hours interval). But the violin plot tail goes more than 23 and less than 0(0th and 23rd margin levels added to graph).
Code:
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()
If you have a look at Violin documentation (https://plotly.com/python-api-reference/generated/plotly.graph_objects.Violin.html) you might need to add to all your Violin initializations a spanmode = 'hard'
. That way your max and min span is set by your data, and not by Silverman’s rule of thumb (bandwidth).
spanmode – Sets the method by which the span in data space where the density function will be computed. “soft” means the span goes from the sample’s minimum value minus two bandwidths to the sample’s maximum value plus two bandwidths. “hard” means the span goes from the sample’s minimum to its maximum value. For custom span settings, use mode “manual” and fill in the span attribute.