For more information about concepts covered in this lesson, you can check out:
Customizing the Colormap and Style
00:00 Customizing the colormap and style. In the scatter plots you’ve created so far, you’ve used three colors to represent low, medium, or high sugar content for the drinks and cereal bars.
You’ll now change this so that the color directly represents the actual sugar content of the items. You first need to refactor the variable
sugar_content_cereal so that they represent the sugar content value rather than just the RGB color values.
00:47 These are now lists containing the percentage of the daily recommended amount of sugar in each item. The rest of the code remains the same, but you can now choose the colormap to use. This maps values to colors.
01:10 The color of the markers is now based on a continuous scale, and this line displays a color bar that acts as a legend for the color of the markers. Onscreen, you can see the resulting scatter plot.
01:27 All the plots you’ve plotted so far have been displayed in the native Matplotlib style, and you can change this style by using one of several available options.
01:36 They can be displayed using the following code.
The plot style is changed by using the function call seen onscreen before calling
02:10 Here, the style has been changed to that of Seaborn, another third-party visualization package. You can see the different style by plotting the final scatter plot you displayed using the Seaborn style.
For more on customizing plots, check out Python Plotting With Matplotlib. Using
plt.scatter() to create scatter plots enables you to display more than two variables. Onscreen, you can see the variables being represented in this particular example.
The ability to represent more than two variables makes
plt.scatter() a powerful and versatile tool. In the next section, you’ll learn even more about how
plt.scatter() can be customized further using NumPy arrays to mask data, allowing creation of complex plots that are still easy to understand.
Become a Member to join the conversation.