Skip to content

Commit

Permalink
codigo para hacer el mapa de argentina interactivo
Browse files Browse the repository at this point in the history
  • Loading branch information
mlares committed Apr 10, 2020
1 parent 09a7e46 commit 97c5cc5
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions mapa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import plotly.express as px
from urllib.request import urlopen
import json
from random import random
import arcovid19 as ar

# DATOS DE ARGENTINA ------------------------

df = ar.load_cases(url=LOCAL_CASES)

d1 = ar.PROVINCIAS
d2 = ar.PROVINCIAS_ALIAS
d = dict(ar.PROVINCIAS, **ar.PROVINCIAS_ALIAS)

# lista con los casos activos

C = []
A = []
R = []
D = []

for k in d.keys():
p = d[k]
C.append(df.loc[(p,'C')].values[-1])
A.append(df.loc[(p,'A')].values[-1])
R.append(df.loc[(p,'R')].values[-1])
D.append(df.loc[(p,'D')].values[-1])



# MAPA DE ARGENTINA ------------------------

with open('provincias_argentina_iso_con_geo.geojson') as f:
arg = json.load(f)

# arreglar cosas a mano
arg['features'][18]['properties']['provincia'] = 'CABA'
arg['features'][7]['properties']['provincia'] = 'Bs As'

prov_ids = []
prov_names = []
prov_values = []
feat = arg['features']

Cs = []
As = []
Rs = []
Ds = []

for i, p in enumerate(feat):
arg['features'][i]['id'] = i
prov = p['properties']['provincia']
prov_ids.append(i)
prov_names.append(prov)
prov_values.append(random())
#print(prov, '...............')
for j, n in enumerate(d.keys()):
if prov in n:
#print(prov, n)
Cs.append(C[j])
As.append(A[j])
Rs.append(R[j])
Ds.append(D[j])


d = {'provincia': prov_names,
'valores': prov_values,
'id': prov_ids,
'C': Cs, 'A': As, 'R': Rs, 'D':Ds
}
df = pd.DataFrame.from_dict(d)




fig = px.choropleth(df, geojson=arg,
locations='id',
color="C",
color_continuous_scale="Viridis",
range_color=(0, 400),
scope="south america",
hover_name="provincia",
labels={'A': 'A', 'R': 'R'}
)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()


0 comments on commit 97c5cc5

Please sign in to comment.