'Plotly: How to manually specify the label of an aggregated field in plotly.py

In Plotly.py histogram and Density heatmaps an aggregation function (histfunc) such as sum or avg may be specified. The x and (unaggregated) y axis labels can be manually specified via the labels dict, but what about the label of the aggregated dimension?

How can the label of the aggregated dimension be manually specified?

Example histogram for code below

import plotly.express as px

df = px.data.tips()
fig = px.histogram(
    df,
    x="total_bill",
    y="tip",
    histfunc="avg",
    labels={"total_bill": "Total bill", "tip": "Tip", "??": "Average tip"},
)
fig.show()

Update/Added

And what about the z axis (?) label for a density heatmap?

Density heatmap

import plotly.express as px

df = px.data.iris()

fig = px.density_heatmap(
    df, x="petal_length", y="petal_width", z="sepal_length", histfunc="avg"
)
fig.show()


Solution 1:[1]

You can use the function update_layout to set y axis label. Example:

px.histogram(
    df,
    x="total_bill",
    y="tip",
    histfunc="avg",
    labels={"total_bill": "Total bill", "tip": "Tip", "??": "Average tip"},
).update_layout(yaxis_title="label for Y axis")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Prats