How to set the number of Decimal places in Plotly violin hover_text

Viewed 180

I have a working Plotly violin plot but the hover_text gives my a lot of decimal places. Is it possible to set the number of decimal places (preferably 2).

This is a full working code from the Plotly webiste, but it illustrates my problem.

import plotly.graph_objects as go

import pandas as pd

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/violin_data.csv")

fig = go.Figure(data=go.Violin(y=df['total_bill'], box_visible=True, line_color='black',
                               meanline_visible=True, fillcolor='lightseagreen', opacity=0.6,
                               x0='Total Bill'))

fig.update_layout(yaxis_zeroline=False)
fig.show() 

This is the relevant section from my code. I have a number of traces so I'm using update_trace to set them all in one go.

figV.add_trace(go.Violin(y=dfNode['H_SEP'],
                        legendgroup='H_SEP', scalegroup='H_SEP', name='Head Sep',
                        line_color='#B233FF'))  
figV.update_traces(box_visible=True, meanline_visible=True,points='all') 

This is what my version looks like. All the information is generated as standard by a violin plot, it's not text I've coded. The numbers are also generated by the violin plot, so it's nothing I can round in my code. I want to keep all the information but I'd like each item to only have 2 decimal places. i.e. Head Sep, mean: 25.96.

enter image description here

0 Answers
Related