我想在地图上绘制地理数据。我有纬度,经度,在我的数据框中还有另一列,是一个人的性别
现在,如果我的人是男性,我想画一个红点,如果我的人是女性,我想画一个绿点
我能够绘制单一颜色,但无法添加基于数据帧列的条件。下面是我的代码
m = Basemap(projection='merc',
llcrnrlat=15, #latitude of lower left hand corner of the desired map domain
urcrnrlat=55, #latitude of upper right hand corner of the desired map domain
llcrnrlon=75, #longitude of lower left hand corner of the desired map domain
urcrnrlon=135, #longitude of upper right hand corner of the desired map domain
lat_ts=0, #latitude of true scale
resolution='c') #resolution of boundary dataset being used - c for crude
m.fillcontinents(color='#191919',lake_color='#000000') # dark grey land, black lakes
m.drawmapboundary(fill_color='#000000') # black background
m.drawcountries(linewidth=0.15, color="w") # thin white line for country borders
# Plot the data
mxy = m(dfPerson["longitude"].tolist(), dfPerson["latitude"].tolist())
m.scatter(mxy[0], mxy[1], s=5, c='#ff0000', zorder=2)
plt.title("China Map")
plt.show()
有没有办法,我可以根据dfPerson['gender']设置颜色c=''ff0000'或''00ff00'='Male'或否
如果我必须选择多种条件,比如男性、女性、RatherNotSay和3种不同的颜色
我自己通过基于过滤器拆分数据帧行解决了这个问题。因此,我没有一个单一的数据帧,而是为我需要的变体准备了尽可能多的数据帧。并将数据帧传递给具有不同颜色的单个m.Scatter函数调用
它解决了这个问题
相关问题 更多 >
编程相关推荐