Locked lesson.
About this lesson
In this video, we discuss how to create your own box plots.
Exercise files
Download this lesson’s related exercise files.
Plotting Box Plots.docx57 KB Plotting Box Plots - Solution.docx
55.6 KB
Quick reference
Plotting Box Plots
Box plots can be created using the same two methods we've discussed earlier.
When to use
Use either of these methods to create a box plot.
Instructions
The first method to create a box plot is:
my_df.plot(kind="box")
To add grid lines to your box plot:
my_df.plot(kind="box", grid=True)
The second method to create a box plot:
my_df.plot.box()
The line in the middle of a box plot designates the Median. The box plot represents your data's quartiles.
Hints & tips
- my_df.plot(kind="box", grid=True)
- my_df.plot.box()
- 00:05 All right, moving right along, in this video, I want to look at box plots.
- 00:08 And box plots are a lot of fun.
- 00:10 And before we get into it, let's come up here real quick and
- 00:13 just check our data one more time.
- 00:15 So we've got a data frame of 50 and 4.
- 00:19 And if we run this again just to make sure,
- 00:22 we've got 4 columns and 50 rows, okay?
- 00:26 So creating box plots is just as easy as all the other plots.
- 00:29 So we can just go my_df.plot, and we can pass in kind = box.
- 00:35 And when we run this, boom, we get our cool little box plots.
- 00:42 And we could pass in most of the attributes that we've done in the past.
- 00:45 So if we wanted to change the size of this, we could go fig size.
- 00:49 And we could set this equal to what 10 and 5, let's say.
- 00:54 And now it's a little bit bigger, these things seem to be a little wider.
- 00:58 We could change the color of this like we can with everything else, so cmap equals.
- 01:02 And let's head back over to our thing here and let's just kind of look around,
- 01:07 let's grab something fun, nippy spectral.
- 01:10 I have to know what that means or what that is.
- 01:13 So let's copy and paste this one Shift+ Enter to run this.
- 01:16 And okay, it's just sort of black and grey.
- 01:18 That's no fun.
- 01:19 Let's see what else.
- 01:21 Jet, rainbow let's try rainbow, make statistics fun.
- 01:28 Okay, so you know whatever, you could change the color, and that's cool.
- 01:32 Now not everything works.
- 01:34 We can't for instance create a legend if we go legend = true,
- 01:37 that doesn't really work here.
- 01:39 We could give this a title, let's say boxplot, whatever.
- 01:44 So now we have a title here.
- 01:47 Now like so many other things, we can do this another way, like we have before.
- 01:52 So we could just call my_df.plot.box, just call the box function.
- 01:59 And again, we can pass in all the same things.
- 02:02 So we can go, fig size = 10 and 5 for instance, it makes it bigger.
- 02:10 And, this is actually kind of cool.
- 02:12 So instead of doing it the first way, if you want to learn more about this
- 02:17 creature, my_df.plot.box and then just come inside your function here and
- 02:21 then Shift+Tab and we can learn more about this if we expand this.
- 02:26 Not only does it teach us the things that we can do inside of our function here,
- 02:31 but it also gives us this cool little description.
- 02:34 So if you're not sure what a box plot is, for instance,
- 02:36 you could just read through here.
- 02:38 A box plot is a method for
- 02:39 graphically depicting groups of numerical data through their quartiles.
- 02:42 So usually, quarter one through four, or in this case, one through three.
- 02:46 The box extends from Q1 to Q3 quartile,
- 02:49 values of the data with a line at the median.
- 02:52 So we see a line right here at the median, right?
- 02:56 So that's always good to look at.
- 02:58 The whiskers extend from the edges of the box to show the range of the data.
- 03:03 So these are the whiskers, these guys,
- 03:05 these straight lines at the top and bottom.
- 03:08 kind of look like whiskers, I guess, right?
- 03:09 And so you could just read through here if you're interested in this stuff.
- 03:12 It even gives you a Wikipedia link to more information if you want to learn more
- 03:17 about them.
- 03:17 So that's kind of cool.
- 03:18 So one thing I will kind of mention here if we add a grid = true, that actually is
- 03:23 kind of useful because you might want to know exactly where the median is and
- 03:27 this grid line will show you exactly where zero is.
- 03:30 So without that grid, you might not know exactly where this green line is,
- 03:35 is it at zero, is it above?
- 03:36 You can eyeball it and seems to be above it, but have the grid lines specifically,
- 03:41 that's even better.
- 03:42 So those are box plots, very cool.
- 03:44 In the next video, we'll look at hex plots.
Lesson notes are only available for subscribers.