Python Plotly choropleth地图报Authentication credentials were not provided错误求助
Plotly choropleth 地图认证报错解决方案
报错原因
你导入的chart_studio.plotly是Plotly官方提供的云服务交互模块,调用py.iplot方法时会默认尝试将生成的图表上传到Plotly云端托管平台,因此需要验证平台账号的身份凭证,才会触发你遇到的认证报错。
修复方案
不需要使用云服务的话,直接改用Plotly的本地渲染接口即可,无需注册账号或提供凭证,按以下步骤修改代码:
- 第一步:替换导入语句,删除
chart_studio相关的导入:
# 原导入替换为以下内容 import plotly.io as pio
- 第二步:替换绘图调用语句,将原来的
py.iplot替换为本地渲染方法,可根据数据情况调整locationmode参数:
data = [dict(type='choropleth',autocolorscale=False,locations=df['name'],z=df['islam'],locationmode="country names",text="test",colorbar= dict(title="heyyo"))] layout= dict(title="Islam adherence in the world ") fig= dict(data=data, layout=layout) # 本地渲染显示图表 pio.show(fig)
补充说明:如果你的
df['name']列存储的是三位ISO国家编码,可保留原locationmode="ISO-3"的设置无需修改。
内容的提问来源于stack exchange,提问作者luthierz
相关产品推荐
相关产品推荐

