Plotting to Maps in Python

import requestsimport geopandas as gpdimport pandas as pdimport matplotlib.pyplot as plt
url = ""response = requests.get(url)response = response.json()response = dict(response)response = response["state"]confirmed = []for i in range(len(response)):   del response[i]['_id']   del response[i]['total']   confirmed.append(response[i]['confirmed'])df = pd.DataFrame.from_dict(response)print(df)
fp = "IND_adm1.shx"map_df = gpd.read_file(fp)map_df.plot()print(map_df)
merged = map_df.join(df)merged = merged.dropna()merged = merged[['name', 'geometry', 'death', 'cured', 'confirmed']]print(merged)
variable = 'confirmed'
vmin = 0vmax = max(confirmed)
fig, ax = plt.subplots(1, figsize=(30, 10))
ax.set_title('Confirmed Cases by State in India', fontdict={'fontsize': '25', 'fontweight' : '3'})sm ='OrRd_r',norm=plt.Normalize(vmin=vmin, vmax=vmax))
sm.set_array([]) # or alternatively sm._A = []. Not sure why this step is necessary, but many recommends itfig.colorbar(sm)merged.plot(column=variable, cmap='OrRd_r', linewidth=0.8, ax=ax, edgecolor='0.8')



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhinav Srivastava

Abhinav Srivastava

Building: Ignite Tournaments / Former: DeFi Alliance, Persistence, Eth India Co