Reputation: 11
I am trying to reduce the decimal places in the text above the histogram bins to 2 places. Here is the graph:
And, here is the code:
fig = px.histogram(df10, x="S_Hour", histnorm='percent', text_auto=True,
labels=dict(S_Hour='Hours of the Day'))
fig.update_layout(yaxis_title="Percents (%)")
fig.update_layout(xaxis = dict(tickmode = 'linear', tick0 = 0, dtick = 1))
fig.update_traces(textfont_size=12, textangle=0, textposition="outside",cliponaxis=False)
fig.show()
Thanks.
Upvotes: 1
Views: 3723
Reputation: 10017
To set the number of decimals in the display, you will need to add texttemplate='%{y:.2f}'
inside your update_trace. This will tell plotly that you want the display of y
values in the format .2f
meaning 2 decimal places after the decimal point. As the data was not available, I have used the plotly tips data to display the same as an example.
import plotly.express as px
df = px.data.tips()
fig = px.histogram(df, x="total_bill", y="tip", histfunc="avg", nbins=8, text_auto=True)
fig.update_traces(textfont_size=12, textangle=0, textposition="outside", cliponaxis=False, texttemplate='%{y:.2f}')
fig.show()
Plot
Upvotes: 4