Python Data Visualization Transcripts
Chapter: Plotly
Lecture: Scatter plots

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now that we've gone through how to visualize data with histograms and box plots will look at the scatter plot to see how the plotly
0:08 API Is expanded to show different types of plots. So for this exercise we use our EPA fuel economy summary.
0:16 I am also adding a vehicle column that set equal to one and I'll walk through why we do that in a little bit later.
0:23 So the first plot I want to show is a scatter plot because I think it's a really good example of a useful data plot.
0:30 That plotly express interactivity that plotly express provides is really useful.
0:37 So we'll create our scatter plot here and I'm gonna zoom out just a little bit so it's easier to see. So now we have a scatter plot of our fuel
0:48 cost versus C02. Each plot is hoverable so I can hover over it and see the data. I can also zoom in and look in more detail
1:00 and then when I want to zoom back out I hit the home so let me walk through what I did here.
1:05 I did a scatter because I didn't want to show electrical vehicles. I excluded those with C02 less than or equal to zero.
1:15 I show the fuel cost on the X axis CO2. on the Y. I added the model for the hover name. So at the top you can see that and then I added the size of the
1:28 circle should be based on the number of cylinders. Also added that to the color.
1:31 So now you can see the gradient for the colors from two cylinder up to 16 cylinders. I also added the hover data so you can see the make year
1:41 cylinders when I hover over it I can see those values. Which is really helpful to understand the data a little more detail.
1:48 One of the other things I like is that you can do a lot of customization on that hover data. So here I wanna show the cylinders and the fuel costs
1:56 but I want to format those so when I click over it, the fuel cost comes through as a dollar sign And the cylinders come through as a
2:03 whole number. And that's because when I passed the hover data, I passed a dictionary until the making year columns should be displayed.
2:11 And that these the cylinders and the fuel cost 08 should have a python formatting string
2:17 applied to it. And this is a really useful thing is your maybe sharing this
2:20 with other people and want to make sure that the numbers are clean and easy to
2:25 understand. The final thing I want to show with scatter plots is that we can also do a scatter matrix so we can plot a two by two of cylinders versus
2:33 fuel cost. So in this case the dimensions are cylinders and fuel cost 08. And I also want to show the color as the make and then now we have
2:43 this nice plot and you can actually, if you select different values, they will get excluded. I have a lot of them on here so you may not be able to see
2:52 that very easily. But those values are interactive here on the legend and you can also sub select and pan and move for those individual plots there.
3:04 So really useful visualizations within plotly, Express and the ability to customize them and add that hover effect.
3:11 So you can understand the individual data points in detail.


Talk Python's Mastodon Michael Kennedy's Mastodon