Locked lesson.
About this lesson
In this video, we explain how to create bar plots using your data.
Exercise files
Download this lesson’s related exercise files.
Plotting Bar Plots.docx57.2 KB Plotting Bar Plots - Solution.docx
55.4 KB
Quick reference
Plotting Bar Plots
There are two main methods for creating bar plots.
When to use
Use either of these two methods when you need to create a bar plot.
Instructions
The first method for creating a bar plot:
my_df.plot(kind='bar')
To stack your bar plot:
my_df.plot(kind='bar', stacked=True)
The second method for creating a bar plot:
my_df.plot.bar()
Hints & tips
- my_df.plot(kind='bar')
- my_df.plot.bar()
- 00:05 Okay, in the last video, we looked at area plots.
- 00:08 In this video, we want to look at bar plots.
- 00:10 So to create a bar plot, we would just
- 00:15 go my_df.plot and then set the kind equal to bar.
- 00:20 And if we run this, we get something that's kind of hard to read because we've
- 00:25 got a lot of data points here.
- 00:27 We got 50. So maybe we want to come up here to our
- 00:30 data and instead of 50 rows, maybe we'll just try 10.
- 00:36 Run that again, run that again.
- 00:38 Here we have zero through nine, that's probably a little more manageable.
- 00:43 And if we run this, we're seeing we have positive and negative values
- 00:48 because we look back at our data, again, we have positive and negative numbers.
- 00:53 So maybe we just want to do absolute values again.
- 00:57 So these will all be positive, just so it's easier to see this.
- 01:01 And here we have our bar plot.
- 01:03 Very cool.
- 01:04 We can also designate these to be stacked.
- 01:07 So we can go stacked=True.
- 01:11 And then now, we get the same thing, it's just with stacked values.
- 01:16 So, this is how you do bar plots.
- 01:18 You could do them another way as well.
- 01:19 We can just go my_df and let's make this an absolute value again.
- 01:25 And then we can call .plot.bar and we get the same value.
- 01:31 That's just sort of a short way to do it.
- 01:33 I kind of liked to do kind='bar' when I do mine, just so I'm clear.
- 01:38 And not all of our charts that we do, you can do a dot off of plot.
- 01:42 Some of them you have to do kind equals whatever.
- 01:46 So I just tend to do it like this.
- 01:47 So, pretty cool.
- 01:49 And inside of here, of course, still we can go stack=True, just like before,
- 01:54 and this becomes true.
- 01:55 We can do all of our other things too, Legend=False.
- 02:01 We do that, our legend disappears.
- 02:04 If we want grid lines, we could go grid=True.
- 02:07 And now we get grid lines.
- 02:12 And just in the last video, if we want a title we can say,
- 02:17 title='Bar Plot' or whatever.
- 02:20 And we get bar plot.
- 02:23 Personally I don't do much like the grid marks for
- 02:26 this, so I'm going to take that off.
- 02:28 And again, you don't have to do absolute values.
- 02:30 If you want your data to go up and down, maybe take off the stack for that.
- 02:36 There we go, all right.
- 02:38 kind of interesting and pretty simple.
- 02:40 So we've got bar plots.
- 02:43 We've got area plots.
- 02:46 We've got the basic histogram.
- 02:48 In the next video, we'll look at line plots.
Lesson notes are only available for subscribers.