# Python Data Visualization Transcripts Chapter: Matplotlib Lecture: Figures and Axes

0:03 Now that we've talked about, how to use the object oriented interface to spend a
0:08 little bit of time actually talking about how to work with figures and axes to plot
0:14 multiple plots. For the first example we're going to create two plots and show how
0:23 we display them together. So first we'll use this command to create a figure and with two axes. And if we want to access each axis,
0:44 Mhm. Put a hissed a gram on each one, and for the second one, just to show an example, we're going to create a second,
0:57 hissed a gram with a larger range. Put a semi colon on there, so nothing else displays. And now you can see that we have to hissed a
1:07 grams in one figure. So one is on axes, zero second, one is on axes. One we've got hissed a Gram using the commands that we've discussed before.
1:18 Now this approach of Acts, If you look at what an Acts is, it's an array. And what I actually prefer to do is a different approach to
1:32 make it a little more explicit. So I'll do everything else the same. And instead of accessing it through a list or an umpire ray,
1:50 We've now assigned a variable. Acts one and I'm sorry, Acts two. Mhm. If we run it, we get the same plot. Now this in and of itself isn't that useful,
2:03 but it shows the concept. Another example that would make it a little more interesting is if we combined a box plot with a history graham.
2:11 So let me show you how to make a box plot first. So here's an example now of the box plot and way to generate it is very
2:25 similar to what we do for hissed a gram, you call the box plot function on the axes, set the title and the white label. And now we have a box plot.
2:35 One of the things I don't like about this box plot is that it's showing all these outlier values. So one of the things I'm going to do is remove those
2:45 and there's a parameter called show fliers. I set that to false. Then I have a little more consistent box plot that
2:54 makes the data easier to to read because we have a much smaller scale. So now let's combine the two. Maybe I'm gonna copy a little bit of code here,
3:09 just two. And while I'm at it I'm going to set some values so it's a little easier to read. And I'm also going to label the box plot.
3:25 The final thing I'm gonna do to make this look a little bit better is I'm
3:30 gonna set vertical equals false. So it will show horizontally and we'll add the labels just to make sure it's nice and clean.
3:49 And there we go. Now we have two plots. So the figure contains axes one and access to access one is a history graham access
3:57 to is a box plot. So we've talked about axes but we haven't talked about a figure yet. So let's show an example of why the figure can be useful
4:07 So I'm gonna copy everything and after all the labels, I'm gonna actually label the figure.
4:18 And we have other options. We can configure such as the font size and I'm also gonna make it bold. There we go. So now we have the M.
4:29 P. G. Distribution and vehicle M P G. At the top and this is all one image, which is really handy. The next thing I'm going to show is how we can
4:39 have a little more control over actually how we create the two different axes. one way to do this so we can specify the number of rows,
4:49 the number of columns. And I'm also going to specify the figure size. So what this will do is create a figure that will have one row and two
4:58 columns. The figure size is nine x 4". So now we have a very different plot. So they're the hissed a gram and box plot are side by side and maybe in
5:19 this case we don't need the vertical there. So we have a nice representation of the MPG and distribution two different ways so that

Talk Python's Mastodon Michael Kennedy's Mastodon