Reputation: 1061
I have a dataframe that looks like this:
Rank Name Pop_2019 Pop_2018 Change latitude longitude TC Risk
0 1 Tokyo 37393129 37435191 -0.0011 35.682839 139.759455 1.0
1 2 Delhi 30290936 29399141 0.0303 28.651718 77.221939 0.0
2 3 Shanghai 27058479 26317104 0.0282 31.232276 121.469207 1.0
3 4 Sao Paulo 22043028 21846507 0.0090 -23.550651 -46.633382 0.0
4 5 Mexico City 21782378 21671908 0.0051 19.432630 -99.133178 0.0
I want to plot the latitude and longitude of cities where 'TC Risk'
= 1. Here is the code I use:
ax = plt.axes(projection=ccrs.PlateCarree())
ax.stock_img()
if data['TC Risk'].any()==1:
ax.scatter(data['longitude'],data['latitude'], transform=ccrs.Geodetic())
However, this simply plots every single latitude and longitude point, not just the ones where 'TC Risk'
= 1. How would I amend my code to accomplish this?
Upvotes: 0
Views: 92
Reputation: 150785
I think you just need boolean indexing and plot:
ax = plt.axes(projection=ccrs.PlateCarree())
ax.stock_img()
plot_data = data[data['TC Risk']==1]
ax.scatter(plot_data['longitude'], plot_data['latitude'], transform=ccrs.Geodetic())
Upvotes: 1