如何在Python中修复“值错误”(按图使用)

时间:2019-04-21 07:18:41

标签: python-3.x plotly

我在python中使用绘图分配,正在创建美国州的地理图,但是当我尝试执行代码时,我遇到了“值错误”,我需要帮助来解决此错误

np.matrix

因为我使用的是Jupyter笔记本,所以我逐个单元地执行代码,尽管得到的结果是:代码不完整:

import plotly.plotly as py
import plotly.graph_objs as go

from plotly.offline import download_plotlyjs,init_notebook_mode,plot,iplot

init_notebook_mode(connected=True)

 data = dict(type = 'choropleth',
location = ['AZ','CA','NY']
,locationmode = 'USA-states'
,colorscale = 'Portland',
text = ['text1','text2','text3'],
z=[1.0,2.0,3.0,]
,colorbar = {'title':'Colorbar title goes here'})

layout = dict(geo={'scope':'usa'})

choromap = go.Figure(data = [data],layout = layout)

1 个答案:

答案 0 :(得分:0)

根据https://plot.ly/python/choropleth-maps/给出的示例,该属性为locations,而不是location。 因此相关代码将如下更改,从location = ['AZ','CA','NY']更改为locations = ['AZ','CA','NY']

data = dict(type = 'choropleth',
locations = ['AZ','CA','NY']
,locationmode = 'USA-states'
,colorscale = 'Portland',
text = ['text1','text2','text3'],
z=[1.0,2.0,3.0,]
,colorbar = {'title':'Colorbar title goes here'})