Data Science Jumpstart with 10 Projects Transcripts
Chapter: Project 10: Making a Snow Report Dashboard with Dash and Plotly
Lecture: Creating a Scatter plot in Plotly

Login or purchase this course to watch this video and the rest of the course contents.
0:00 In this video I'm going to demonstrate scatter plotting with Plotly. So this works very similar to Matplotlib. I'm going to say do a scatter plot,
0:09 specify what column I want in the X&Y and what column I want to use to color that, and there is our scatter plot. So what is this showing us?
0:16 It's showing us each month how much snow is on the ground. Is this the world's greatest
0:20 scatter plot? No, not necessarily. I am seeing things line up on columns. That's because month, even though it is numeric,
0:28 is basically like a category here. I'd probably want to change the alpha. Let's try and change the alpha of this.
0:35 Turns out that alpha doesn't work with Plotly, sadly. And I believe it's opacity here. Let's try this with opacity. And there we go.
0:49 So I would also probably jitter this using our jittering code that we saw in other places,
0:57 but you get the idea here. A nice feature of Plotly is that if you hover over a point, it will tell you what the value is of that.
1:04 Okay, the next thing I'm going to do is I'm going to do a scatter plot of temperature of observation versus snow depth and color that by month,
1:14 what the temperature is, how much snow is on the ground, and then what month it is. Here's our plot. Let's see what's going on here.
1:26 We're going from purple to yellow. So as we are purple, it looks like we have a low temperature. We have a lot of snow on the ground.
1:34 As we start going to like a pinkish, we're getting a higher temperature, less snow on the ground. You can see that somewhere over here, it gets to
1:44 this month six-ish where we get pink and orange. We have high temperatures, no snow on the ground.
1:55 You can see it sort of comes out there and then it starts coming back to orange.
1:58 As we get back to orange, we are getting into this fall time frame where it gets colder
2:05 and we start to get snow on the ground. So we're sort of seeing this sort of cycle where it gets colder, snow builds up, it gets warmer, snow melts,
2:12 and then summer there is no snow on the ground and then it comes back. I would like to use a cyclical color map to demonstrate that.
2:19 I'm not aware of how to do that in pandas, but we should be able to do that. Using some Plotly code, just with Plotly itself.
2:28 Let's see how to do this using just Plotly code. Here's the code to do this with Plotly. Let's look at the plot.
2:35 This makes it a little bit more clear. I use Twilight right here, which is a cyclical color map. It goes from white to purple to this dark color
2:45 to a reddish color and back to white. So we're seeing in the cold of winter,
2:51 that's this whitish pinkish color. We have cold temperatures, snow on the ground.
2:56 As we move into February, it warms up a little bit, but snow builds up. And then we're seeing the darker blues as we get into summer.
3:04 It starts to melt. We have less snow on the ground. And then we get into when it's warm enough, there is no snow on the ground.
3:12 The snow is melted. And then you can see that this is sort of transitioning back into colder temperatures. We're starting to get snow build up.
3:19 I think this is an interesting scatter plot. I wish that there was a way to do this from patterns directly. Let's just look at the code here.
3:26 Basically, we're saying make this figure. And the data in the X is going to be
3:31 the temperature of observation. The data in the Y is going to be the snow depth.
3:35 And we're passing in this marker dictionary where we can specify the color scale using the Twilight color scale.


Talk Python's Mastodon Michael Kennedy's Mastodon