The power of hue
1. The power of hue
Now we've got a nice looking barplot.2. Our nice barplot
Here's what it looks like again, and on the right is a reminder of what the final table was that is powering this plot. But what if we wanted to break this bar graph down not only by store, but also by products sold? Here,3. A more granular barplot
on the left, is the more granular data we need to create this plot, and it should look familiar: it's our summary table of fruit sold for each store, sorted by store and product name.4. A more granular barplot
And on the right is what our new graph will look like. On the x-axis still remains each store, on the y-axis still remains revenue, but now, each product name from each store is broken out. And what allows us to accomplish this visual breakdown is Hue.5. Hue
Hue is an optional argument to our call to sns-dot-barplot that tells Seaborn what to break up color by. In the last line of code here, we've written hue-equals-product-underscore-name with product-underscore-name in quotations to tell Seaborn this dataset variable is how color should be distributed in our graph. And in our graph, we see not only the revenue for each fruit per store, but also a legend in the upper right-hand corner of our figure that displays what color corresponds to what product name.6. plt.legend()
Note that, to place the legend in the desired location outside of the graph, we must also make a call to plt-dot-legend with the optional argument bbox-underscore-to-underscore-anchor equal to one-comma-one in parentheses. This one-comma-one in parentheses is an example of a tuple, which is another collection type in Python that we'll not cover in this course. This line may be helpful to you in the future as you use hue in your graphs.7. All together
Here is a final look at the code needed to create this plot. We first set a style, then we make our call to sns-dot-barplot, with x set to store, y to revenue, data equal to our dataset, fruit-underscore-store-underscore-summary, and our new argument hue set to product-underscore-name. Next, we call plt-dot-legend with the proper arguments to place our legend in the upper-right of our figure. And lastly, we have all of our previous code for plot title, axis labels, despining, and showing. Now it's8. Your turn!
your turn to break down visuals with hue.Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.