基于数据帧列值的底图散点图颜色

2024-06-23 19:15:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在地图上绘制地理数据。我有纬度,经度,在我的数据框中还有另一列,是一个人的性别

现在,如果我的人是男性,我想画一个红点,如果我的人是女性,我想画一个绿点

我能够绘制单一颜色,但无法添加基于数据帧列的条件。下面是我的代码

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种不同的颜色


Tags: ofthe数据map颜色domain绘制color
1条回答
网友
1楼 · 发布于 2024-06-23 19:15:02

我自己通过基于过滤器拆分数据帧行解决了这个问题。因此,我没有一个单一的数据帧,而是为我需要的变体准备了尽可能多的数据帧。并将数据帧传递给具有不同颜色的单个m.Scatter函数调用

它解决了这个问题

相关问题 更多 >

    热门问题