我实际上是想在地图上绘制点。每个点都与cmd = new OleDbCommand("SELECT * FROM users WHERE [id] = " + Session_ID, conn);
中0到1000之间的值相关联。我只想用比例红色成分对点进行着色,正如您在此可重现的例子中所看到的那样:
sumlist
问题是地图上没有显示所有点。我认为import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
m = Basemap(projection='kav7',lon_0=0,lat_0=0,resolution='l')
m.drawcoastlines()
m.fillcontinents(color='#ddaa66',lake_color='#7777ff')
m.drawmeridians(np.arange(0.,420.,60.))
m.drawparallels(np.arange(-90.,120.,30.))
m.drawmapboundary(fill_color='#7777ff')
lon_prox=[-36.4,-38.5,-77,-71,-19.8,-69.5,-10.09,-4.93,9,-91.3,-85.92,-114.2,-109.3,103,-110.1,-42.6,1.16,-20.1,-23.2,-18.2,-17.95,-17.7,-10.1,-5.87]
lat_prox=[76.6,72.6,80.7,69.87,64.6,81.33,30.845,58.14,46,35.15,30.45,38.9,37.5,71.29,40,71.7,40.34,57.44,56.1,66.54,66.53,66.55,30.85,56.67]
x,y=m(lon_prox,lat_prox)
sumlist=[276,554,39,0,2,1,107,14,10,32,0,992,933,17,897,39,0,0,0,0,0,24,111,0]
for i in range(len(x)):
col='#%02x%02x%02x' % (int((255*sumlist[i])/1000),0,0)
m.scatter(x[i],y[i],color=col,zorder=10)
plt.show()
参数可以帮助我,因为当我将它设置为zorder
(我之前没有放任何东西)时,我没有出现过一些点。但我真的不明白10
是什么。我知道这个问题不应该很难解决,但我花了两个小时就完成了。
提前致谢,
Smich。
答案 0 :(得分:2)
Scatter()将x,y,c列表或数组作为参数。试试这段代码:
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
#import numpy as np
# defind figure dimension
fig = plt.figure(figsize=(12, 8))
m = Basemap(projection='kav7',lon_0=0,lat_0=0,resolution='l')
m.drawcoastlines(color='gray')
m.fillcontinents(color='#ddaa66',lake_color='#7777ff')
m.drawmeridians(range(0,420,60))
m.drawparallels(range(-90,120,30))
m.drawmapboundary(fill_color='#7777ff')
lon_prox=[-36.4,-38.5,-77,-71,-19.8,-69.5,-10.09,-4.93,9,-91.3,-85.92,-114.2,-109.3,103,-110.1,-42.6,1.16,-20.1,-23.2,-18.2,-17.95,-17.7,-10.1,-5.87]
lat_prox=[76.6,72.6,80.7,69.87,64.6,81.33,30.845,58.14,46,35.15,30.45,38.9,37.5,71.29,40,71.7,40.34,57.44,56.1,66.54,66.53,66.55,30.85,56.67]
x,y=m(lon_prox, lat_prox)
sumlist=[276,554,39,0,2,1,107,14,10,32,0,992,933,17,897,39,0,0,0,0,0,24,111,0]
# prep colors
hexcolors = []
for i in range(len(x)):
hexcolors.append('#%02x%02x%02x' % (int((255*sumlist[i])/max(sumlist)),0,0))
# scatter takes x,y,c arrays as parameters
m.scatter(x, y, c=hexcolors, s=60, zorder=10, alpha=0.7)
plt.show()