When creating density heatmaps / 2d histograms, there is an automatic aggregation that can take place, which also sets the name as it appears on the legend. I'm trying to change how that aggregation is displayed on the legend. Consider the following example, taken directly from the plotly docs:
import plotly.express as px
df = px.data.tips()
fig = px.density_heatmap(df, x="total_bill", y="tip")
fig.show()
How can I pass a string that will alter the "count" as it appears on the legend?
I've tried with .update_layout(legend_title_text = "Test string")
but did not manage to get anywhere.
Try setting the title.text
property of coloraxis_colorbar
inside layout.
df = px.data.tips()
fig = px.density_heatmap(df, x="total_bill", y="tip")
fig.update_layout(coloraxis_colorbar=dict(
title=dict(
text="Number of Bills per Cell")
)
)
fig.show()
You can also define this in a single line using coloraxis_colorbar_title_text
.
import plotly.express as px
df = px.data.tips()
fig = px.density_heatmap(df, x="total_bill", y="tip")
fig.update_layout(coloraxis_colorbar_title_text="Number of Bills per Cell")
fig.show()