python - Plotting using basemap and descartes doesn't show PolygonPatch -


i can plot shapely buffered points so:

import matplotlib.pyplot plt matplotlib.collections import patchcollection mpl_toolkits.basemap import basemap shapely.geometry import point 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() 

this results in following plot:

enter image description here

however, if try plot these points using basemap, don't appear:

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 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 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() 

enter image description here

what doing wrong?

it if provided working example, image cannot reproduced code supplied.

if plot basemap on mercator projected map, coordinates supply should in same projection. plotting wgs84 lat/lon on mercator projected map, thats not going work. buffer apply points expressed in map coordinates, meters instead of degrees.

the map object provides easy conversion with:

x,y = m(lon,lat) 

so change point creation to:

point(m(lon, lat)).buffer(1000) 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -