Python Data Visualization Transcripts
Chapter: Matplotlib
Lecture: Scatter plots

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The next type of chart we'll talk about is a scatter plot. Let's get one started here. It's called scatter.
0:10 And we're going to explicitly say what the X and Y axis are. In this case we want to plot the fuel cost versus the displacement.
0:30 The other attribute I'd like to introduce is alpha, which is essentially how transparent the values are and we're going to pass in colors based
0:42 on the number of cylinders. And while we're at it, let's go ahead and set some labels and titles.
0:58 So now we have a nice scatter plot that shows us that as the engine displacement increases, the fuel cost increases which makes sense.
1:08 A larger engine is going to use more fuel. The colors are telling us how many cylinders are in the engine.
1:16 So we've got a lot of information that we're portraying in this plot.
1:21 Let's go through another example of more customization that we can do on this plot and make it even more informative. So we'll keep the basic plot.
1:35 Now we're going to set the X Label and the Y label and I'm going to show how to do that and increase
1:40 the font size as well. We talked about using the formatter so let's format this access so it's a currency so maybe we show the dollar sign and a comma
1:57 to make it a little easier to read. And for that we'll use the set major formatter.
2:05 The other thing I'm gonna do to make it look a little cleaner is to change
2:09 the font size and the rotation on our labels and we'll just change the label size on the Y axis And now I'm going to add a vertical line at $3500.
2:28 So let's say part of our analysis is we have this target of $3500 that we're trying to get to or annotate on our graph.
2:37 So this says axes vertical line. So we need to tell where to draw that line. We're gonna draw it at 3500, tell it we want to be black.
2:50 We can tell what line style. There's a whole bunch of different line styles that matplot lib supports. Maybe we want to label this.
2:57 So we'll have a line at 3500. So what this says is at a text annotation And we'll call the the text as target of 3500. The X.
3:13 Y coordinates will pass a tuple of 3500 and 2. So it should be kind of right in here. Size of the text should be 16.
3:22 And then the final thing I'm going to do is add a grid so we can see what it looks like. I think that looks nice.
3:31 See if I made any typos forgot to tell it. Put the major formatter on the X axis spelled mis-spelled label size.
3:51 And one of the other things I noticed now is I'd like to make this figure a little bit bigger. I think it's kind of cramped.
3:59 So let's update this to fixed size. Will you run it? There we go. Now. We have a bigger figure. So let's walk through again. What we've done,
4:10 We created our figure with one axis and the figure size is 9 by 7. We added a scatter plot. We the alpha is the transparency so that you can
4:21 see more of the plots and the color is based on the cylinders. So notice that it's the displacement versus the fuel cost.
4:29 But the cylinders are shown as the color. We set our X and Y labels. We included a size for the font to make it a little more readable.
4:41 We set the formatter on the X axis so that the currency comes through with a dollar sign and a comma.
4:48 We also set the tick parameters so we rotated the labels and the size. We added this vertical line on the chart That shows the target of 3500.
5:02 And then we turned on the grid so this highlights all of the configuration options that you have available to you in matplot lib.
5:11 And once you start to get the hang of it and start to look through the
5:14 documentation. It's relatively straight forward but is verbose some of the future libraries that we'll be talking about to do make a lot of these easier.


Talk Python's Mastodon Michael Kennedy's Mastodon