1 回答
TA贡献2019条经验 获得超9个赞
我举个例子。coloraxis_colorbar您可以在更新布局中使用字典。
这里,
tickvals- 颜色条中的枚举值
ticktext- 根据值显示的文本
from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
counties = json.load(response)
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
dtype={"fips": str})
import plotly.express as px
fig = px.choropleth(df, geojson=counties, locations='fips', color='unemp',
color_continuous_scale="Viridis",
range_color=(0, 12),
scope="usa"
)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0},coloraxis_colorbar=dict(
title="unemployment rate",
thicknessmode="pixels",
lenmode="pixels",
yanchor="top",y=1,
ticks="outside",
tickvals=[0,4,8,12],
ticktext=["Low", "Low Medium", "High Medium", "High"],
dtick=4
))
fig.show()
现在来解决你的问题,
使用tickvals=[0,1,2,3]
和
ticktext=['0 - no measures', '1 - recommend closing', '2 - require closing (only some levels)', '3 - require closing all levels']
添加回答
举报