Python Data Visualization Transcripts
Lecture: Basic shorthand API
0:00 Now let's go through some examples of how to use altair, I have a notebook set up reading in my file and as we discussed,
0:09 I have import altair as ALT and then I read in my file so now we have our data frame.
0:17 So here's the first example of creating a altair visualization and when I run it in
0:25 this instance I get this error and way down at the bottom it says the error is max rows error. The number of rows in your dataset is greater than the
0:34 maximum allowed. So we've been using a fairly large data set and as we mentioned altair will by default encode all that data into a jupiter notebook.
0:45 You may have some scenarios where that notebook gets too large and you don't like that
0:50 The way we're gonna get around this is we're gonna put a cell above here We talked about the data transformers.
0:58 So we're going to enable one called the data server. And what that will do once we run that it is enabled now and now when
1:06 we run our plot we actually get the visualization. So what is happening behind the scenes is there's now a local data server running on
1:16 my system that will serve up the image in my jupyter notebook. There are other options available to you put these out here.
1:25 So put this in our notebook just so we can see it so you can see that there is a Jason, a CSV, there's the data server that we're using.
1:32 It's a little bit of personal preference about how you want to do this. But I'm going to use the data server for our examples.
1:40 So let's restart and run everything just so we make sure everything works as expected. So we walk through this a little bit.
1:48 But here's what we've done with altair. Now we have told it to create a chart with our data frame and create a
1:56 circle and then the X axis is the displacement and the Y axis is fuel cost 08. So let's see what happens if we take the exact same code.
2:08 And instead of doing mark circle we do mark point. So you can see, I have the same plot but instead of circles, I have points which are open circles.
2:21 So that starts to get some examples. Now let's do another example where we can start to add a little bit more information
2:30 here. Now we're going to show the displacement fuel costs but we're also going to
2:36 say adjust the color by the drive and we'll also say the shape by the drive So now we have a plot that is similar,
2:46 all the same data points, but now we have squares and circles for two wheel drive and four wheel drive vehicles are also encoded as different colors.
2:56 Let's give another example of a different kind of plot using the same api shorthand. If we want to do a histogram,
3:04 we have to do something a little bit different. So we'll want to market as a bar chart across the X axis,
3:11 we want the fuel cost, but then around the why we wanted to count the number of instances. So now we have a nice histogram with the fuel
3:24 costs. Like we've done in some of our other visualizations and I think you'll agree that the plots that altair creates are really nice.
3:32 They've got some nice formatting on the numbers, they look clean, they look very modern and I think you're gonna find that you
3:40 like this and your business customers are also going to enjoy these types of visualizations.