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

时间:2018-04-08 01:04:29

标签: python polygon shapefile matplotlib-basemap

我正在尝试在Basemap中填充多边形颜色。但是我总是得到错误get_axis_bgcolor function was deprecated in version 2.0并且颜色不会显示出来。我使用pip install basemapconda install -c conda-forge basemap重新安装basemap,如here in python3.6中所述。 shapefile can be found here。和原始的shapefile 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)

错误消息的完整回溯:

/Users/miniconda3/lib/python3.6/site-packages/mpl_toolkits/basemap/__init__.py:1707: MatplotlibDeprecationWarning: The get_axis_bgcolor function was deprecated in version 2.0. Use get_facecolor instead.
  if self.projection not in ['geos','ortho','nsper']:
/Users/miniconda3/lib/python3.6/site-packages/mpl_toolkits/basemap/__init__.py:1563: MatplotlibDeprecationWarning: The get_axis_bgcolor function was deprecated in version 2.0. Use get_facecolor instead.
  x = len(yy)*[self.xmin]; y = yy.tolist()

我的结果如下:

enter image description here

0 个答案:

没有答案
相关问题