import altair as alt
# if in notebook
alt .renderers .enable ("notebook" )
alt .Chart (df ).mark_bar ().encode (
x = alt .X ('Brain Weight' ,bin = True ,title = "Brain Weight Binned" ),
y = "count()"
).properties (
width = 200 ,
height = 200 ,
title = "Histogram of Brain Weight"
)
scatter = alt .Chart (df ).mark_circle ().encode (
x = "Body Weight" ,
y = "Brain Weight"
)
trends_bar = alt .Chart (trends ).mark_bar ().encode (
x = "search_term" ,
y = "sum(value)" ,
color = "search_term"
)
trends_line = alt .Chart (trends ).mark_line ().encode (
x = alt .X ("date:T" ,timeUnit = "yearmonth" ),
y = "sum(value)" ,
color = "search_term"
)
countries = alt .topo_feature ("https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json" , feature = "countries" )
background = alt .Chart (countries ).mark_geoshape (
fill = "lightgrey" ,
stroke = "white"
)
temp = weather_df .groupby ("city" ).mean ().reset_index ()
cities = alt .Chart (temp ).mark_point ().encode (
latitude = "lat" ,
longitude = "long" ,
size = alt .value (1 ),
color = alt .Color ("temp" ,scale = alt .Scale (range = ["red" ,"orange" ,"lightblue" ]))
)
background + cities
cities_viz = alt .Chart (cities ).mark_text (
font = "Cardo" ,
fontSize = 11 ,
fontStyle = "italic" ,
dx = 3
).encode (
latitude = "lat" ,
longitude = "lon" ,
text = "city"
).properties (
width = 800
)
troops_viz = alt .Chart (troops ).mark_trail (
strokeCap = "SQUARE"
).encode (
latitude = "lat" ,
longitude = "lon" ,
color = alt .Color ("direction" ,scale = alt .Scale (domain = ['A' , 'R' ],range = ["#EBD2A8" ,"#888888" ])),
size = alt .Size ("survivors" ,scale = alt .Scale (range = [1 ,75 ])),
detail = "division"
).properties (
width = 800
)
select_search_term = alt .selection_single (encodings = ["x" ])
trends_line = alt .Chart (trends ).mark_line ().encode (
x = alt .X ("date:T" ,timeUnit = "yearmonth" ),
y = "sum(value)" ,
color = "search_term"
).transform_filter (
select_search_term
)
trends_bar = alt .Chart (trends ).mark_bar ().encode (
x = "search_term" ,
y = "sum(value)" ,
color = "search_term"
).properties (
selection = select_search_term
)
trends_bar | trends_line
selection = alt .selection_interval (encodings = ["x" ])
trends_line = alt .Chart (trends ).mark_line ().encode (
x = alt .X ("date:T" ,timeUnit = "yearmonth" ),
y = "sum(value)" ,
color = "search_term"
).transform_filter (
selection
)
trends_line_small = alt .Chart (trends ).mark_line ().encode (
x = alt .X ("date:T" ,timeUnit = "yearmonth" ),
y = "sum(value)" ,
color = "search_term"
).properties (
height = 50 ,
selection = selection
)
(trends_line & trends_line_small )
Overriding 5000 rows limitation
temp = weather_df .groupby ('country' ).mean ().reset_index ()