Plotting to Maps in Python

import requestsimport geopandas as gpdimport pandas as pdimport matplotlib.pyplot as plt
url = "https://covid19-india-adhikansh.herokuapp.com/states"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.axis('off')
ax.set_title('Confirmed Cases by State in India', fontdict={'fontsize': '25', 'fontweight' : '3'})sm = plt.cm.ScalarMappable(cmap='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')

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

An Overview on a Data Scientist’s Profile

Let’s take a look at WaveTrend with Crosses [LazyBear’s Indicator]

Tools for Big Data

4 Common Problems in Data Projects, Part 1

Why trust machine?

Pit Bull Pic

Visualising the albums of Wu-Tang Clan

Analysis for everything?

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

More from Medium

Automating from BigQuery to Tableau Extracting and Publishing Hyper Files via Python and Pandas

Performing Analysis of Meteorological Data

Visual Cheatsheet for Plot/Chart Types Based on Data Column Types

Visual Cheatsheet for Plot Types based on data column types

Machine-learning assisted vaccine sentiment and misinformation detection dashboard — part 1