I was wondering if there was a way to have graphic objects violin plot not display the trace’s kde, mean, median, quantiles etc.
This information is displayed whenever the mouse is not hovering over a precise data point, even though I have entered a totally different hovertemplate, which is displayed when data points are hovered upon.
The unwanted information is shown on the following image:
It is related but I thought I would open another topic for this subject, since it is specific to violin plots: whereas the previous one was about the trace id being displayed when hovering over the information, this one is about violin plot specific information being displayed when not hovering over the data points but on the trace.
Hope it made sense to do so.
def create_violinplot(*args):
fig = go.Figure()
for column in plot_scaled.columns:
#Retrieving some data to be displayed for each point: the label it is issued from and if there is an alert
alert_array = alert_matrix[column].map(lambda a: 'Alert' if a else 'No alert')
data = np.concatenate(
(np.stack(arrays=[labels, alert_array], axis=1),
np.array([ arg[column].map(lambda o: arg.name + 'says YES' if o else arg.name + 'says NO') for arg in args ]).T), # The args are boolean matrices we want to be retrieving data from
axis=1)
fig.add_trace(go.Violin(y=df[column],
name=column,
points='all',
pointpos=0,
customdata=data,
jitter=0.2)
)
hovertemplate = '<extra></extra>Sample %{customdata[0]} <br>%{customdata[1]}'
#Create the hover template: the three first columns of the customdata are necessarily alocated whereas the following ones depend on the number of arguments
for i in range(3, len(args)+2):
hovertemplate += '<br>%{customdata['+str(i)+']}'
#And finally put all of that information in the hovertemplate of the traces
fig.update_traces(hovertemplate=hovertemplate,
showlegend=False)
return fig
Now when the cursor hovers over a data point, the hovertemplate is displayed:
However, when the cursor is on or in the vicinity of the violin, it displays this default information which I would like to get rid of:
I’m sorry but I cannot use this function without data.
To realize what is going on, I need the effective fig definition, to inspect fig.data, and deduce why unnecessary information is displayed on hover.
To hide tooltips when hovering violin (not the point inside), set hoveron='points' at all traces using fig.update_traces.
The default value of hoveron is ‘violin+points’ that will show the tooltips whenever you hover points or the violin.