python - 无法在 plotly express choropleth 中隐藏颜色条
问题描述
我已经尝试关注讨论这个问题的文档和各种帖子,但我一无所获。我正在从 plotly 示例中渲染 choropleth 县地图,但我似乎无法弄清楚如何隐藏颜色条。这是我尝试过的:
import plotly.express as px
from urllib.request import urlopen
import json
import pandas as pd
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
counties = json.load(response)
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
dtype={"fips": str})
fig = px.choropleth(
df,
geojson=counties,
locations='fips',
color='unemp',
color_continuous_scale="Viridis",
range_color=(0, 12),
scope="usa",
labels={'unemp':'Unemployment'}
)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0}, coloraxis=dict(showscale=False))
fig.update(layout_coloraxis_showscale=False)
fig.update_traces(showlegend=False)
fig.update(layout_showlegend=False)
fig.update_traces(showscale=False)
fig.show()
我的结果总是一样的:
解决方案
我建议你检查你的情节版本使用
import plotly
plotly.__version__
如果小于5.1.0
那么我建议您使用以下 pip 命令更新它
pip install -Iv plotly==5.1.0
我只使用了你的代码,使用这个特定版本的 plotly 我得到了一张没有颜色条的地图
推荐阅读
- python - DurationField 或 Timedelta
- ios - 如何使用 ApiAi Pod 从 Swift 向 Dialogflow 发送访问令牌
- javascript - 运行js超时的插件
- python - VS Code 和 Python -> 缺少自动完成功能
- python - 如何创建没有索引错误的 folium.chloropleth 地图?
- vue.js - 如何使用 Vue-i18n 创建一个更改语言的按钮
- python - 使用多个参数的字典使旧代码单线程代码适应多处理
- pip - 如何为通过 anaconda environment.yml 安装的 pip VCS 包指定源目录
- python - scrapy twisted.internet.error.ReactorNotRestartable
- c++ - 我的 C++ 文件需要一个“while”来代替 if。最后它期望一个'('