Python Data Visualization Transcripts
Chapter: Altair
Lecture: Longhand API

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now I'm going to introduce a more complex API. That's available for altair that allows you to do even more customization
0:09 of your visualizations. So let's take a look again at the histogram that we created a while back. And if we look at this part of the issue
0:19 might be we're not really bending the data. So we're actually counting each individual example the fuel cost and how many there are.
0:28 And if we wanted to really create a histogram we should break it into bends So we need to do that in this example.
0:38 Now we have a histogram where it's counting in by bins from 0 to 1000 3,4 and so on for this visualization,
0:47 we use the same format of creating a chart with our data frame marking a bar and encoding. But instead of just saying X equals and Y equals.
0:57 We use the alt.x function and tell it to use the fuel cost. We're telling it that is a quantitative value. And we want to bend the data.
1:08 We're going to also tell it to count and that it's a quantitative value. So this gives us a lot more functionality.
1:15 Now we can do many different things with this api structure for instance, let's say if we want to control the bin structure so that maybe we have a
1:26 little more detail here. Let's go through another example And here we have a little
1:34 bit more of a useful histogram where we're breaking it down between zero and 5000, we're assigning a step of 250 and we're telling it to count here.
1:44 So I'm kind of mixing and matching some of the different approaches. Let me clean this up to show how you can still use some of the Shorthand
1:55 but using that alt.x and alt.y for more control over the visualizations. So let's continue doing this with some of our scatter plots that we've done.
2:08 So now we'll do another scatter plot with displacement and fuel cost. We're gonna specify that you color it by the number of cylinders and in this case
2:19 I specified cylinders as an ordinal. So you'll see how the colors are shaded as we go from zero or no cylinders up to higher cylinder number. Now,
2:31 let's do this just a similar plot. But instead of saying the cylinders are ordinal,
2:37 let's call them quantitative. You'll see a much different plot where now it's not a distinct grouping here, it's a gradient here,
2:49 let's bring this all together with another example where we're going to look at our displacement
2:54 and fuel cost and now we're going to say the cylinders are nominal and so we
2:59 have a much different color break down here where there is a very clear distinction by color based on the number of cylinders.
3:09 So once again this is showing how altair interprets the data and the information you give
3:18 it about the type of variables and changes the visualization to try and be more useful for the end user. In the next section,
3:30 we'll go through these different types, so don't worry too much about what they are right now. I will cover them in just a moment.

Talk Python's Mastodon Michael Kennedy's Mastodon