Reputation: 2318
I am making a ConvexHull in python, by a set of latitude and longitudinal positions. Then I want to plot the points, alongside the ConvexHull in a basemap. Everything works fine if I plot them in a normal plot without a map,as I follow the instructions from http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.ConvexHull.html#scipy.spatial.ConvexHull. When I try to plot them with a basemap, I just get the regular plot. What do I do wrong?
import matplotlib.pyplot as plt
import numpy as np
from 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)
with con:
cur = con.execute("SELECT DISTINCT latitude, longitude FROM MessageType1 where latitude>= 70.55 and latitude<= 70.7 and longitude >= 27.72 and longitude <= 28.416 limit 100 ")
points = [[float(x[1]), float(x[0])] for x in cur]
points = np.array(points)
hull = ConvexHull(points)
x,y = map(points[:,0], points[:,1])
plt.plot(x, y, 'o')
for simplex in hull.simplices:
x,y = map(points[simplex,0], points[simplex,1])
plt.plot(x,y, 'k-')
plt.show()
Upvotes: 0
Views: 643
Reputation: 56
You need to add some methods after setting up the Basemap to draw the map features. Eg:
map.drawcoastlines()
map.drawstates()
map.drawcountries()
map.drawmapboundary()
See the documentation: http://matplotlib.org/basemap/users/geography.html
Upvotes: 1