I am using matplotlib's Basemap to plot points on a world map. I am extracting the latitude and longitude values from a two columns cordb['Latitude'] and cordb['Longitude'] in a CSV file. Also, the color of the points in the plot is being made based on the corresponding value in the cordb['level'] column in the same CSV as shown in the below figure.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
cordb = pd.read_csv(r'data.csv')
lat = cordb['Latitude'].values
lon = cordb['Longitude'].values
level = cordb['level'].values
fig = plt.figure(figsize=(20, 8))
#basemap
m = Basemap(projection='cyl', resolution='h',
llcrnrlat=10, urcrnrlat=70,
llcrnrlon=-140, urcrnrlon=-40, )
m.drawcoastlines(linewidth=0.3)
m.scatter(lon, lat, latlon=True,
c= level ,
cmap='jet', s=4, alpha=1)
# create colorbar and legend
plt.colorbar(label= 'level')
plt.legend()
plt.show()
I have another column cordb['state']in the CSV file, whose elements are some thing like this Texas, Alaska, Washington,.... Here, how to change the marker of the points based on its corresponding state and plot its legend along with the existing one.
