Python Data Visualization Transcripts
Chapter: Plotly
Lecture: Annotations

Login or purchase this course to watch this video and the rest of the course contents.
0:00 For this final exercise. I wanted to develop a single plot and do some enhancements and updates to it to support more customized visualization.
0:10 So the plot I'm going to create is a strip plot which is gonna show the
0:16 fuel cost 08 average fuel cost for these vehicles broken down by the class summary.
0:23 So now we have this plot that shows the estimated fuel cost by class summary. Let me show the code that we actually used to do that.
0:32 So I developed my strip plot and then I specified a range between 300 and 4000 to bring it in a little bit tighter to focus on some of the key values
0:41 I updated the layout to remove the legend and then I updated the Y and X axes
0:47 to have different titles that are clearer for people that are viewing this plot. So now that I have this,
0:53 I'm gonna add some additional annotations on two areas. First I want to highlight this pickup of 1150,
1:02 it looks like a little bit of an outlier because all the other pickup price, fuel costs are in this 1550-1600 range.
1:10 And then the other thing I wanted to do is add an annotation So that we can say for the sake of this discussion, if you are greater than 3500,
1:19 you are an inefficient vehicle because of that that cost being higher. So we want to indicate these on our plot.
1:27 So now we have this customized annotated plot where we have the outlier value here specifically
1:33 called out and then I have a range highlighted for inefficient vehicles. So let's look at the code that we did that.
1:40 So we talked about updating the layout and the axis. Now I add an annotation at 11 50 where the Y values pick up,
1:49 I can tell the text to use and to show an arrow and the type of arrowhead. And then plotly make sure it puts it an offset so that
1:58 you can view it appropriately. And then finally I want to add a vertical rectangle with these X zero and X one.
2:04 So that's where to start from 3500 to 4000. I want to fill it in with a light salmon color and call these inefficient vehicles
2:12 and put that label at the bottom. And then finally I wanna display it and save this image as an Svg.
2:18 So now we have this customized visualization with the key points that you want to show created and saved as an SVG so that if you want to share it
2:28 via email, put it in a power point presentation or some other way to share
2:32 it. You have that value and can repeat this when you want to run it on other slides of your data.

Talk Python's Mastodon Michael Kennedy's Mastodon