首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python /Plotly/Geopandas

Python /Plotly/Geopandas
EN

Stack Overflow用户
提问于 2018-09-27 11:13:23
回答 1查看 3.1K关注 0票数 3

我一直收到这个错误,并在网上阅读了其他人的入门文章,

代码语言:javascript
复制
ImportError: geopandas, pyshp and shapely must be installed for this figure factory.

Run the following commands to install the correct versions of the following modules:

pip安装geopandas==0.3.0

pip安装pyshp==1.2.10

pip安装shapely==1.6.3

代码语言:javascript
复制
If you are using Windows, follow this post to properly install geopandas and dependencies:http://geoffboeing.com/2014/09/using-geopandas-windows/

If you are using Anaconda, do not use PIP to install the packages above. Instead use conda to install them:

conda plotly安装

conda安装geopanda

代码语言:javascript
复制
The thing is , I have installed plotly/geopanda via the methods above and it still does not work , but when I import plotly, geopand alone it does not throw an error. really when I break down my code  below, this line is what is throwing the error: `ff.create_choropleth` - my full code is below: 

```javascript

绘图导入,geopandas

将plotly.plotly作为py导入

将plotly.figure_factory作为ff导入

将numpy导入为np

将熊猫作为pd导入

导入xlrd

df_sample = pd.read_excel('popdata.xlsx') #读取数据

values =df_sample‘’Change‘.tolist()#读取文件中包含的值

fips = df_sample' FIPS '.tolist() #读入FIPS代码

colorscale = ["#171c42","#223f78","#1267b2","#4590c4","#8cb5c9","#b6bed5","#dab2be",

代码语言:javascript
复制
          "#d79d8b","#c46852","#a63329","#701b20","#3c0911"]

endpts = list(np.linspace(-75,75,len(colorscale) - 1)) #为您的数据确定合适的范围

#fig = ff.create_choropleth(

fips=fips,values=values,colorscale=colorscale,show_state_data=True,binning_endpoints=endpts,#如果你的值是一个数字列表,你可以将你的值放入半开区间

County_outline={‘颜色’:'rgb(255,255,255)',‘宽度’:0.5},

legend_title='%变化‘,title=’1980-2014年间疾病变化%‘

#)

Py.plot(图,filename='diseasechange')

代码语言:javascript
复制
EN

回答 1

Stack Overflow用户

发布于 2018-09-27 16:35:05

不是先使用import plotly figure_factory as ff,然后使用ff.create_choropleth,而是尝试这样:

代码语言:javascript
复制
# import necessary libraries
import geopandas
import shapely
import shapefile
import plotly
from plotly.figure_factory._county_choropleth import create_choropleth
import xlrd
# Check your version
print(plotly.__version__, geopandas.__version__,shapely.__version__,shapefile.__version__)
# Data
df_sample = pd.read_excel('popdata.xlsx') # Read in your data
values = df_sample['Change'].tolist() # Read in the values contained within your file
fips = df_sample['FIPS'].tolist() # Read in FIPS Codes

colorscale = ["#171c42","#223f78","#1267b2","#4590c4","#8cb5c9","#b6bed5","#dab2be",
              "#d79d8b","#c46852","#a63329","#701b20","#3c0911"]

endpts = list(np.linspace(-75, 75, len(colorscale) - 1)) # Identify a suitable range for your data

fig = create_choropleth(
   fips=fips, values=values, colorscale=colorscale, show_state_data=True, binning_endpoints=endpts, # If your values is a list of numbers, you can bin your values into half-open intervals
    county_outline={'color': 'rgb(255,255,255)', 'width': 0.5}, 
    legend_title='% change', title='% Change in disease between 1980-2014'
)
# Plot in offline mode and save plot in your Python script folder
plotly.offline.plot(fig, filename='diseasechange.html')

此外,如果您在使用import shapelyimport shapefile时遇到问题,则需要安装它

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52528889

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档