Python Data Visualization Transcripts
Chapter: Plotly
Lecture: Line bar area

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now we're gonna look at some additional plot types and I'm going to create a new
0:08 data frame that has the average fuel economy and the number of cars by year.
0:14 And this will be a simple data frame that we'll use for plotting a line chart and some other plot types. So to walk through this I am grouping by I'm
0:24 taking my data frame, grouping it by year in class. I don't want it to have a separate hierarchical index.
0:32 That's why I set this to false and I'm aggregating our fuel cost to get them average and the vehicle to get the total number.
0:40 This is why I added the vehicle column to our data frame so that we can count the number of vehicles per year.
0:45 I'm rounding it to make it a little bit easier and this is our data frame So you can see for each year I can see the cars and what the
0:53 average fuel cost was and how many fit into that. So now that we have this data, let's create a line chart to show what that averages over time.
1:04 So now this is an interesting chart. We can look at the wagons over time and see how the fuel cost decreases and
1:14 then we can do that for each of these other groups. So let me walk through what the line does. So I use my average by year.
1:19 Class data frame, the X axis is the year. The wise the fuel cost. I'm telling it to group the lines together by class
1:29 summary because if you see this data, we have multiple different entries per year.
1:36 So it groups it by class summary which makes this really easy to show all these
1:42 together and then we have our similar hover effects that we have seen earlier. So that's a good example for the line chart.
1:51 And what's interesting what I like about plotly express that I can change it instead of just doing a line chart.
1:56 Maybe I want to do an area chart and let's see what that looks like. So now the same basic code except I just changed it to PX.area shows
2:05 an area chart so we can kind of see what that looks like over time. And then if you want to see a good old bar chart, change it to show a bar chart.
2:16 So now I can see for each year by each class how that the number of vehicles per year. So in this case I said that the X.
2:25 Is the year and then Y is vehicle.
2:28 So if we just want to see how many vehicles there are per year in each class then it is very easy to see in this bar chart.


Talk Python's Mastodon Michael Kennedy's Mastodon