python - Plot ConvexHull in basemap -
i making convexhull in python, set of latitude , longitudinal positions. want plot points, alongside convexhull in basemap. works fine if plot them in normal plot without map,as follow instructions http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.convexhull.html#scipy.spatial.convexhull. when try plot them basemap, regular plot. do wrong?
import matplotlib.pyplot plt import numpy np mpl_toolkits.basemap import basemap map = basemap(projection='merc', resolution = 'c', area_thresh = 40, llcrnrlon=27.72, llcrnrlat=69.41, urcrnrlon=28.416, urcrnrlat=70.95) con = lite.connect(databasepath) con: cur = con.execute("select distinct latitude, longitude messagetype1 latitude>= 70.55 , latitude<= 70.7 , longitude >= 27.72 , longitude <= 28.416 limit 100 ") points = [[float(x[1]), float(x[0])] x in cur] points = np.array(points) hull = convexhull(points) x,y = map(points[:,0], points[:,1]) plt.plot(x, y, 'o') simplex in hull.simplices: x,y = map(points[simplex,0], points[simplex,1]) plt.plot(x,y, 'k-') plt.show()
you need add methods after setting basemap draw map features. eg:
map.drawcoastlines() map.drawstates() map.drawcountries() map.drawmapboundary()
see documentation: http://matplotlib.org/basemap/users/geography.html
Comments
Post a Comment