Reputation: 640
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?
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()
And what about the z
axis (?) label for a 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()
Upvotes: 0
Views: 3824
Reputation: 35230
The title of the color bar can be set as follows.
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()
Upvotes: 1
Reputation: 634
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")
Upvotes: 2