1. Building up the barplot
Alright, you can make a plot! But how can we improve how this plot looks?
2. Previous barplot
Here's a reminder of what our plot looks like so far. But you may want to add some more information to this graph, like a title, or more official-looking labels for your x and y-axes.
3. Adding labels
Recall in the last lesson when we used sns-dot-barplot to create the graphic and plt-dot-show to display the graphic. In between these two functions, we can use additional functions to build up our graph piece by piece. Note the comments now between sns-dot-barplot and plt-dot-show. This is where we can add to our plot. Let's fill these comments with code to improve our plot.
4. Adding a title with plt.title()
First, let's add a title to our plot using the plt-dot-title function. You can pass this function a title you'd like, here just 'Revenue by Store', in quotations, and now you can see on the top of our graphic our plot's title appears.
5. Adding an x-axis label with plt.xlabel()
Similar to the title function, plt-dot-x-label allows us to designate a label for the x-axis. Here we've simply capitalized the S in Store. Let's do something a little bit more noticeable to the y-axis label.
6. Adding an y-axis label with plt.ylabel()
Lastly for labeling, we can adjust our y-axis label with plt-dot-y-label. Here we have designated our y-axis label as 'Revenue (USD)'. Now that we have more pleasing labels, we can add an additional step or two before plt-dot-show to improve the overall quality of the graphic.
7. Removing unwanted borders with sns.despine()
Next, we'll use a handy function from the seaborn package, sns-dot-despine, without any arguments, to remove the top and right borders from our graphic. This adds some well-received openness to the graph. We could also pass additional arguments like 'bottom equals True', for example, to remove the bottom border from this graphic. But for right now, we'll leave it as is.
8. Adding style with sns.set_style()
Lastly, we can set a style preset to improve the overall quality of the graphic by calling sns-dot-set-underscore-style, and then passing the name of one of Seaborn's style presets in quotes. For the remainder of this course, we'll use the 'whitegrid' preset.
Note that sns-dot-set-style is exceptionally placed before the call to sns-dot-barplot. If we want to use a style preset, it must be set before we begin creating our plot with sns-dot-barplot.
9. Side by side
With that, here is a side-by-side comparison of our initial graphic from the previous lesson and our final result from this lesson. With better labels, less borders, and a preset style, this is a graph we can confidently share with colleagues.
10. Your turn!
Now it's your turn to make better-looking plots in the exercises.