-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_map.py
61 lines (54 loc) · 1.77 KB
/
create_map.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import plotly.express as px
import json
import pandas as pd
import plotly.io as pio
import plotly.graph_objects as go
from datetime import date,timedelta
#Create inida map using go.Choropleth
def create_india_map(df,color,name,day):
#load geojson file for india
india_states = json.load(open("./data/states_india.geojson", "r"))
state_id_map = {}
for feature in india_states["features"]:
feature["id"] = feature["properties"]["state_code"]
state_id_map[feature["properties"]["st_nm"]] = feature["id"]
fig = go.Figure(data=go.Choropleth(
locations=df["id"], #common in both file (datafile and geojson file)
z=df['total'], #thing you want to see
text=df['states'], #text when hover map
geojson=india_states,
colorscale=color,
autocolorscale=False,
reversescale=True,
marker_line_color='peachpuff',
marker_line_width=0.5,
colorbar_title=f'{name} Cases',
colorbar=dict(
thickness=15,
len=0.55,
bgcolor='rgba(255,255,255,0.6)',
)
))
fig.update_geos(fitbounds="locations", visible=False)
fig.update_geos(
visible=False,
projection=dict(
type='miller',
parallels=[86.472944444, 98.172805555556],
rotation={'lat': 24, 'lon': 80}
),
)
fig.update_layout(
title=dict(
text=f"{name} COVID-19 Cases in India State wise till {day}",
xanchor='center',
x=0.5,
yref='paper',
yanchor='bottom',
y=1,
pad={'b': 10}
),
margin={'r': 0, 't': 70, 'l': 0, 'b': 0},
)
# fig.show()
pio.write_image(fig, f'./image/{name}.png',width=800,height=700)