在版本2.0中,不推荐使用get_axis_bgcolor函数在basemap中填充多边形

2024-06-01 07:40:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着在底图中填充多边形。但是我总是得到错误get_axis_bgcolor function was deprecated in version 2.0,颜色就不会显示出来了。我使用pip install basemap和{}重新安装{},如{a1}所述。形状文件can be found here。以及原始形状文件are provided here。在

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from matplotlib.patches import Polygon
import shapefile
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111)

m = Basemap(projection = 'mill', llcrnrlat=40.47,urcrnrlat=40.95,\
        llcrnrlon=-74.28,urcrnrlon=-73.70,resolution='f') # mill = Miller cylindrical cordinates, resolution c or f
m.drawcoastlines()
# m.drawcounties()
m.drawrivers()
m.fillcontinents(color='w', lake_color = 'lightslategrey')
m.drawmapboundary()
m.readshapefile('~/Desktop/Capstone2017/taxi_zones/taxi_zones_WGS84','taxi_zones_WGS84')

sf=shapefile.Reader('~/Desktop/Capstone2017/taxi_zones/taxi_zones_WGS84')

shape_ex = sf.shape(13)
x_lon = np.zeros((len(shape_ex.points)))
y_lat = np.zeros((len(shape_ex.points)))
for ip in range(len(shape_ex.points)):
    x_lon[ip] = shape_ex.points[ip][0]
    y_lat[ip] = shape_ex.points[ip][1]

region = np.dstack((x_lon, y_lat))[0]
poly = Polygon(region, facecolor='r', edgecolor='k')
ax.add_patch(poly)

错误消息的完整回溯:

^{pr2}$

我的结果如下:

enter image description here


Tags: inimportiplen错误nppointsex