Python Data Visualization Transcripts
Chapter: Altair
Lecture: Concat charts
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
For this next set of exercises, we will show some additional examples of how to create multiple graphs in altair and also
0:10
make them interactive. So I've started a new notebook with our imports.
0:14
I'm using our data server data transformers so we can deal with the large data sets
0:19
And the first thing I'm going to show is how to make the scatter plot that we've shown in the past a little more interactive.
0:29
So with this new plot, it looks similar to what we've done in the past
0:33
with displacement and fuel cost. But what's nice now is I can hover over individual
0:39
points and see what the make model and year is and this command is enabled or
0:45
this functionality is enabled by using the tool tip so I can tell it which columns to use in this case the make model and year.
0:53
And then I also tell the chart to be interactive. So in addition to the hovering that I can do here,
1:00
I can also do some panning and zooming of the chart. So this is really cool. And one of the key differentiating factors of altair versus
1:10
some of the other tools that we've looked at so far. The next thing I'm going to show you is how to put multiple charts together in
1:18
one visualization When we did this in mat plot lib, we would use the figures and axes.
1:23
But here what we do in altair is create each chart and then we can concatenate them together in this case I use a shortcut.
1:32
I use the vertical bar to say put chart one on the left and chart two on the right and concatenate them on the horizontal axis.
1:41
So now I have this mark tick chart as my first chart and then the bar chart with my bending equals true as my second chart and it puts them side by
1:52
side. If we want the charts to be vertically stacked, we can use the ampercent and now we have chart two on top and chart one
2:02
on the bottom. And remember altair has two different interfaces. The vertical bar or the pipe that we used previously can also be done with it
2:11
alt.hconcat or horizontal con cat. And we could also do that with a vertical cat. So now we have the two charts on top of each other.
2:20
So this is a really convenient way to build a visualization with all of the different charts in a single image versus two separate images.