python : matplotlib.Basemap.scatter 不显示地图上的所有点
python : matplotlib.Basemap.scatter does not show all points on map
我实际上是在尝试在地图上绘制点。每个点都与 sumlist
中 0 到 1000 之间的值相关联。我只想用成比例的红色分量给点上色,正如你在这个可重现的例子中看到的那样:
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
时(我之前什么也没放)一些我没有出现的点。但是我真的不明白 zorder
是什么意思。我知道这个问题应该不难解决,但我花了两个小时才解决。
提前致谢,
斯密
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()
我实际上是在尝试在地图上绘制点。每个点都与 sumlist
中 0 到 1000 之间的值相关联。我只想用成比例的红色分量给点上色,正如你在这个可重现的例子中看到的那样:
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
时(我之前什么也没放)一些我没有出现的点。但是我真的不明白 zorder
是什么意思。我知道这个问题应该不难解决,但我花了两个小时才解决。
提前致谢,
斯密
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()