-
Notifications
You must be signed in to change notification settings - Fork 0
/
vac.py
85 lines (71 loc) · 6.02 KB
/
vac.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import altair as alt
cor=['#13A891','#F09001','#9653F5','#34A52B','#F52232','#F5C129']
def vaq1(df):
# Seletor de continente
click = alt.selection_multi(fields=['continent'])
# Base
danone = alt.Chart(df)
#escalas
xscale = alt.Scale(domain=(0, 100))
yscale = alt.Scale(domain=(0, 100))
# heatmap
retas= danone.mark_rect().encode(x = alt.X('people_vaccinated_per_hundred',bin=True,scale=xscale,axis = alt.Axis(titleFont='Courier',
title='People Vaccinated (%)')),
y = alt.Y('people_fully_vaccinated_per_hundred',bin=True,scale=yscale,axis = alt.Axis(titleFont='Courier',
title='People Fully Vaccinated (%)')),
color= alt.Color('count()',legend=alt.Legend(orient='bottom-right',titleFont='Courier'))).properties(width=400,height=400
).transform_filter(click)
# scater plot
point = danone.mark_circle(stroke='black',strokeWidth=0.7).encode(
alt.X('people_vaccinated_per_hundred', scale=xscale,axis=alt.Axis(grid=True,domain=False,title=None,labels=False,ticks=False)),
alt.Y('people_fully_vaccinated_per_hundred', scale=yscale,axis=alt.Axis(grid=True,domain=False,title=None,labels=False,ticks=False)),
color=alt.Color('continent',legend=None,scale=alt.Scale(range=cor)),#scheme='dark2')),
opacity=alt.condition(click,alt.value(1),alt.value(.1)),
size = alt.Size('people_fully_vaccinated',scale=alt.Scale(type='log',
range=(1,175)),legend=alt.Legend(orient='right',title='Fully Vaccinated - log',
titleFont='Courier',labelFont='Courier'))
).properties(width=400,height=400)
# tooltips scater
point1 = point.encode(opacity=alt.value(0),tooltip=['location',
alt.Tooltip('people_vaccinated_per_hundred',title='Vaccinated %'),
alt.Tooltip('people_fully_vaccinated_per_hundred',title='FULL vac. %'),
alt.Tooltip('people_fully_vaccinated',title='FULL vac'),'date']).transform_filter(click)
# scater + tooltips
points=(point+point1).add_selection(click)
# legendas
l1 = danone.mark_rect().encode(y=alt.Y('continent',axis=alt.Axis(domain = False,ticks=False,
orient='left',labelFont='Courier',
title=None)),
color=alt.condition(click,
alt.Color('continent:N',legend=None,
scale=alt.Scale(range=cor)),#scheme='dark2')),
alt.value('lightgray'))
).properties(width=400,height=100,).add_selection(click)
l2 = danone.mark_rect().encode(x=alt.X('continent:N',scale = alt.Scale(),
axis=alt.Axis(domain = False,ticks=False,
orient='bottom',labelFont='Courier',
title=None)),
color=alt.condition(click,
alt.Color('continent:N',legend=None,
scale=alt.Scale(range=cor)),#scheme='dark2')),
alt.value('lightgray'))
).properties(width=100,height=400,).add_selection(click)
# marquinhas
x_ticks = danone.mark_tick(color = 'lightgrey').encode(
alt.X('people_vaccinated_per_hundred', axis=alt.Axis(labels=False, domain=False, ticks=False,title=None),scale=xscale),
alt.Y('continent', title='', axis=alt.Axis(labels=True, domain=False, ticks=False,title=None)),
)
y_ticks = danone.mark_tick(color = 'lightgrey').encode(
alt.X('continent', title='', axis=alt.Axis(labels=True, domain=False, ticks=False,title=None)),
alt.Y('people_fully_vaccinated_per_hundred', axis=alt.Axis(labels=False, domain=False, ticks=False,title=None),scale=yscale),
)
return alt.vconcat((l1 + x_ticks),
alt.hconcat((retas+points).resolve_scale(x = 'independent',y='independent'),
(l2+y_ticks),spacing=0),
spacing=0).properties(title='Vaccine around the World').configure_view(strokeWidth=0
).configure_title(fontSize=30,
font='Courier',
anchor='end',
color='gray',
orient='left'
)