简体   繁体   中英

Plotly: How to change the title of the colorbar using bx.bar?

I can't figure out how to change the title of the color-legend in plotly. (Example Image, blue circle)

链接到示例图像

If you're using px.bar with settings that produce a colorbar, use:

fig.layout.coloraxis.colorbar.title = 'another title'

Plot:

在此处输入图片说明

Complete code:

import plotly.express as px
data = px.data.gapminder()

data_canada = data[data.country == 'Canada']
fig = px.bar(data_canada, x='year', y='pop',
             hover_data=['lifeExp', 'gdpPercap'], color='lifeExp',
             labels={'pop':'population of Canada'}, height=400)

fig.layout.coloraxis.colorbar.title = 'another title'

fig.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM