底图找不到 .shp 文件
Basemap cannot locate .shp file
我正在尝试加载一个 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 文件夹中有 Neighborhoods-MI.shp、Neighborhoods-MI.shx、Neighborhoods-MI.prj 和 Neighborhoods-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:
您必须指向实际 shapefile 的名称,而不是包含它的文件夹,因此在您的情况下它将是“../Desktop/Neighborhoods-MI/Neighborhoods-MI”
您当前指向的只是包含该文件的文件夹。
我正在尝试加载一个 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 文件夹中有 Neighborhoods-MI.shp、Neighborhoods-MI.shx、Neighborhoods-MI.prj 和 Neighborhoods-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:
您必须指向实际 shapefile 的名称,而不是包含它的文件夹,因此在您的情况下它将是“../Desktop/Neighborhoods-MI/Neighborhoods-MI”
您当前指向的只是包含该文件的文件夹。