我试图加载shapefile并使用底图对其进行绘制,但是每次尝试加载shapefile底图时,都会出现以下错误:即使.shp文件位于我提供的文件夹中,它也无法定位.shp文件。它的路径。有人可以告诉我我在做什么错吗?
我的代码:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
map = Basemap(llcrnrlon=-86.637575,llcrnrlat=41.855400,urcrnrlon=-82.946169,urcrnrlat=45.116972,
resolution='l', projection='tmerc', lat_0 = 43.513523, lon_0 = -84.660036)
map.drawmapboundary(fill_color='aqua')
map.fillcontinents(color='#ddaa66',lake_color='aqua')
map.drawcoastlines()
# Shape file location
map.readshapefile('../Desktop/Neighborhoods-MI', 'Neighborhoods')
Neighborhoods-MI文件夹中包含Neighbourss-MI.shp,Neighborss-MI.shx,Neighborss-MI.prj和Neighborss-MI.dbf文件。我还尝试过仅使用“ Neighborhoods-MI”代替文件的完整路径,但是没有任何效果。
注意:我也收到了过时的警告,但我认为这不是问题
/anaconda3/lib/python3.6/site-packages/mpl_toolkits/basemap/__init__.py:1708: MatplotlibDeprecationWarning: The axesPatch function was deprecated in version 2.1. Use Axes.patch instead.
limb = ax.axesPatch
/anaconda3/lib/python3.6/site-packages/mpl_toolkits/basemap/__init__.py:1711: MatplotlibDeprecationWarning: The axesPatch function was deprecated in version 2.1. Use Axes.patch instead.
if limb is not ax.axesPatch:
答案 0 :(得分:2)
您必须指向实际shapefile的名称,而不是指向包含该文件的文件夹,因此在您的情况下,它将为'../ Desktop / Neighborhoods-MI / Neighborhoods-MI'
您当前指向的只是包含文件的文件夹。