ShapelyFeature.Reader 不在 Cartopy 中工作

ShapelyFeature.Reader not Working in Cartopy

我是运行下面的简单代码:

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import cartopy.crs as ccrs
from cartopy.io import shapereader as shpreader
from cartopy.feature import ShapelyFeature

fname = r'C:/cb_2018_us_cd116_500k.shp'

ax = plt.axes(projection=ccrs.Robinson())
shape_feature = ShapelyFeature(shpreader(fname).geometries(),
                                ccrs.PlateCarree(), facecolor='none')
ax.add_feature(shape_feature)
plt.show()

我收到以下错误:

shape_feature = ShapelyFeature(shpreader(fname).geometries(),
TypeError: 'module' object is not callable

有人可以帮忙吗?

我 运行 Python 3.6 Pycharm Windows 10

shapereader as shpreader 是模块,您想要的是 class 存在于该模块中,即 cartopy.io.shapereader.Reader

shape_feature = ShapelyFeature(shpreader.Reader(fname).geometries(),
                                ccrs.PlateCarree(), facecolor='none')

这个图书馆:

from cartopy.io import shapereader as shpreader 

适合我

尝试更改目录

这个:fname = r'C:/cb_2018_us_cd116_500k.shp'

为:fname = 'C:user/yourname/cb_2018_us_cd116_500k.shp'