A Post Exploring Altair
A tutorial of fastpages for Jupyter notebooks.
This Is The Tool We Have
I'm trying out the fastpages in hopes that I wont have to spend the time building out my own website toolset. I've been slowly building something out of Wagtail which is a really just Djnago with some bells. The real allure though is going to be the Notebook conversions - specifically the Data Visualizations. The library for interactive version is Altair and we're going to explore some data!
iris = data.iris()
iris
First lets see the graph - and then we'll discuss the functions
alt\
.Chart(iris)\
.mark_point()\
.encode(
x='sepalLength',
y='sepalWidth',
color='species',
tooltip = ['species', 'petalLength', 'petalWidth']
)\
.interactive()
It is interesting to note that - per the Docs - :
Create a basic Altair/Vega-Lite chart.
Although it is possible to set all Chart properties as constructor attributes, it is more idiomatic to use methods such as
mark_point()
,encode()
,transform_filter()
,properties()
, etc.
.. which means that it's found a way to do something similar to the R Programming Languages pipe operator. For reference, it would looks something like this:mtcars %>%
ggplot(aes(wt, mpg)) +
geom_point(aes(colour = factor(cyl)))
First we tell altair to make a chart using the dataset we're using:
.Chart(iris)
... which is then followed by the kind of graph that we're after - in this case we're after a scatter plot:
.mark_point()
... and then we tell it where everything belongs.
.encode(
x='sepalLength',
y='sepalWidth',
color='species',
tooltip = ['species', 'petalLength', 'petalWidth']
)
Of interest is that you can add data from the other columns easily using the tooltip
without having to add anything extra.
Layering information which is relevant but lacks a meaningful graphic representation was a nice touch.
Then of course, you allow users to interact with it via:
.interactive()
Lets see what this post looks like on the blog!