Python 使用底图和笛卡尔绘制不';不显示多边形补丁
我可以绘制一些形状良好的缓冲点,如下所示:Python 使用底图和笛卡尔绘制不';不显示多边形补丁,python,matplotlib,matplotlib-basemap,shapely,descartes,Python,Matplotlib,Matplotlib Basemap,Shapely,Descartes,我可以绘制一些形状良好的缓冲点,如下所示: import matplotlib.pyplot as plt from matplotlib.collections import PatchCollection from mpl_toolkits.basemap import Basemap from shapely.geometry import Point from descartes import PolygonPatch fig = plt.figure() ax = fig.add_s
import matplotlib.pyplot as plt
from matplotlib.collections import PatchCollection
from mpl_toolkits.basemap import Basemap
from shapely.geometry import Point
from descartes import PolygonPatch
fig = plt.figure()
ax = fig.add_subplot(111)
minx, miny, maxx, maxy = [-6.108398, 49.61071, 1.669922, 58.972667]
w, h = maxx - minx, maxy - miny
x, y = (-0.117588, 51.513230)
correct = Point(x, y).buffer(0.5)
ax.add_patch(PolygonPatch(correct, fc='#cc00cc', ec='#555555', alpha=0.5, zorder=5))
ax.set_xlim(minx - 0.2 * w, maxx + 0.2 * w)
ax.set_ylim(miny - 0.2 * h, maxy + 0.2 * h)
ax.set_aspect(1)
ax.add_patch(patch)
plt.show()
这将导致以下绘图:
但是,如果我尝试使用Basemap绘制这些点,它们不会出现:
bounds = [-6.108398, 49.61071, 1.669922, 58.972667]
minx, miny, maxx, maxy = bounds
w, h = maxx - minx, maxy - miny
fig = plt.figure()
ax = fig.add_subplot(111)
m = Basemap(
projection='merc',
ellps = 'WGS84',
llcrnrlon=minx - 0.2 * w,
llcrnrlat=miny - 0.2 * h,
urcrnrlon=maxx + 0.2 * w,
urcrnrlat=maxy + 0.2 * h,
lat_ts=0,
resolution='i')
m.drawcoastlines()
m.drawmapboundary()
# set axes limits to map crs
min_x, min_y = m(minx, miny)
max_x, max_y = m(maxx, maxy)
corr_w, corr_h = max_x - min_x, max_y - min_y
ax.set_xlim(min_x - 0.2 * corr_w, max_x + 0.2 * corr_w)
ax.set_ylim(min_y - 0.2 * corr_h, max_y + 0.2 * corr_h)
ax.set_aspect(1)
# add known good coordinate
x, y = m(-0.117588, 51.513230)
correct = Point(x, y).buffer(1.)
ax.add_patch(PolygonPatch(correct, fc='#cc00cc', ec='#555555', alpha=0.5, zorder=5))
plt.show()
我做错了什么?如果您提供了一个工作示例,您的图像将无法用您提供的代码复制 如果在墨卡托投影地图上使用Basemap进行打印,则提供的坐标应在同一投影中。您正在墨卡托投影地图上绘制WGS84 lat/lon,这将不起作用。应用于点的缓冲区也以地图坐标表示,即米而不是度 地图对象提供了以下轻松转换:
x,y = m(lon,lat)
因此,将点创建更改为:
Point(m(lon, lat)).buffer(1000)
如果您提供了一个工作示例,您的图像将无法使用您提供的代码进行复制,这将有所帮助 如果在墨卡托投影地图上使用Basemap进行打印,则提供的坐标应在同一投影中。您正在墨卡托投影地图上绘制WGS84 lat/lon,这将不起作用。应用于点的缓冲区也以地图坐标表示,即米而不是度 地图对象提供了以下轻松转换:
x,y = m(lon,lat)
因此,将点创建更改为:
Point(m(lon, lat)).buffer(1000)
将缓冲区大小更改为米会导致该点可见。谢谢将缓冲区大小更改为米会导致该点可见。谢谢