Plotly:如何在 plotly.py 中手动指定聚合字段的标签

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

Plotly.py histogram and Density heatmaps 中可以指定聚合函数 (histfunc),例如 sumavgx 和(未聚合的)y 轴标签可以通过 labels 字典手动指定,但是 聚合维度的标签呢?

如何手动指定聚合维度的标签?

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

那么 density heatmapz 轴 (?) 标签呢?

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()

您可以使用函数update_layout设置y轴标签。示例:

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")

彩条的标题可以设置如下。

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.layout['coloraxis']['colorbar']['title'] = 'new colorbar_title'
fig.show()