我通过一组纬度和纵向位置在python中制作一个ConvexHull。然后我想在底图中绘制ConvexHull旁边的点。如果我在没有地图的普通情节中绘制它们,一切正常,因为我按照http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.ConvexHull.html#scipy.spatial.ConvexHull的说明进行操作。当我尝试使用底图绘制它们时,我只是得到了常规绘图。我做错了什么?
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()
答案 0 :(得分:1)
您需要在设置底图后添加一些方法来绘制地图要素。例如:
map.drawcoastlines()
map.drawstates()
map.drawcountries()
map.drawmapboundary()