I am drawing a correlation matrix of the Titanic dataset.
df_corr = df.corr()
Originally, the matrix looks like this:
fig = ff.create_annotated_heatmap(
z=df_corr.to_numpy(),
x=df_corr.columns.tolist(),
y=df_corr.index.tolist(),
zmax=1, zmin=-1,
showscale=True,
hoverongaps=True
)
# add title
fig.update_layout(title_text='<i><b>Correlation not round</b></i>')
I want to round the float number, so they display less digits after the .
dot.
The current workaround is actually round the pandas dataframe before input.
df_corr_round = df_corr.round(3)
fig = ff.create_annotated_heatmap(
z=df_corr_round.to_numpy(),
x=df_corr.columns.tolist(),
y=df_corr.index.tolist(),
zmax=1, zmin=-1,
showscale=True,
hoverongaps=True
)
# add title
fig.update_layout(title_text='<i><b>Correlation round</b></i>')
But the workaround also rounds the text when I hover mouse over. I want hover text in full detail while display text are round.
Can I display less digits on each cell without changing the input dataframe ?