Python Data Visualization Transcripts
Chapter: Altair
Lecture: Additional examples of the basic API

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's go through some other examples of different kinds of plots just to hammer home the API. So this is kind of a useful one.
0:11 We're going to look at our fuel type summary and we're going to use mark tick So now we have this nice summary of the barrels and how it breaks down
0:24 by the different fuel types. Another one that we could do that would be pretty interesting that we've done in some other cases would be a box plot.
0:34 So let's go and create one and call it mark box plot. And we're gonna see that the box plot looks a little funny in this case that
0:44 there is a box plot but they're all on top of each other and that's because
0:49 it's looking at the year and it doesn't quite understand what that year variable is.
0:54 So we need to give it some pointers so that it looks the way we expect So what we're going to do is we're gonna tell it that the year is
1:09 an ordinal or categorical variable and then the fuel cost is quantitative. And what that's gonna do then is break out the year here from 2000 to 2020
1:23 and then show all of our box plots like we would expect. So this is a really important concept for altair.
1:33 This usage of interpreting what the values are and the plots actually changing depending on the
1:40 different types. And I'll go through some more examples of that in just a moment
1:44 One other kind of interesting point about altair is that we can let's say create a bar chart. In this case we want to create a bar chart but we
1:57 want to actually calculate the mean of each value. So this will tell us the mean fuel cost by year.
2:08 So we can see all of our years and then what the average fuel cost is But if we look at the year once again,
2:15 you could tell that Altair doesn't understand that the year is the year that it's just trying to treat it as a numerical value.
2:24 So let's tell it once again what to do. And now we have our years 2000 through 2020 and our main fuel cost.
2:34 So what I think is really important to understand with altair is it is doing that
2:39 behind the scenes interpretation of the different types of data and most of the time it's
2:45 pretty good. But because this year is just an imager in our data, we need to tell it to treat it as a Ordinal value.

Talk Python's Mastodon Michael Kennedy's Mastodon