For more information about concepts covered in this lesson, you can check out:
Customizing the Colormap and Style
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.
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.