Using Color Bars to Improve Data Readability
In this lesson, we will learn how to use a color bar to improve the readability of our data.
We'll cover the following
What is the colorbar
?
While legend
helps us identify the different elements of a chart, the feature only works for discrete data. If the data is continuous, how could we display it on the legend
? colorbar
can help us. The colorbar
maps the values of an interval to the colors of a range. The user can then distinguish the approximate range of the data by color. colorbar
is a very useful and beautiful feature.
The simplest way to draw a color bar is by calling colorbar()
.
Notice: In this lesson, the
colorbar()
is called from the figure object. Let’s see some of the parameters required bycolorbar
.
mappable
: Thematplotlib.cm.ScalarMappable
described by the colorbar.cax
: The axes object onto which the color bar will be drawn.
What is matplotlib.cm.ScalarMappable
?
In short, ScalarMappable
is a class to map scaler data to RGBA. This class requires two parameters:
norm
: A normalize class, which typically maps a range number to the interval[0, 1]
.cmap
: The colormap is used to map normalized data values to RGBA colors. Matplotlib has already defined many color maps, which we can use by callingplt.get_cmap()
with a name as the parameter.