Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.
The matplotlib.colors.Colormap class belongs to the matplotlib.colors module. The matplotlib.colors module is used for converting color or numbers arguments to RGBA or RGB.This module is used for mapping numbers to colors or color specification conversion in a 1-D array of colors also known as colormap.
The matplotlib.colors.Colormap class is a base class for all scalar to RGBA mappings. Generally colormap instance are used to transform data values (floats) from interval 0-1 to their respective RGBA color. Here the matplotlib.colors.Normalize class is used for scaling the data. The matplotlib.cm.ScalarMappable subclasses heavily use this for data->normalize->map-to-color processing chain.
class matplotlib.colors.Colormap(name, N=256)
- name: It accepts a string that represents the name of the color.
- N: It is an integer value that represents the number of rgb quantization levels.
Methods of Class:
- colorbar_extend = None : If the colormap exists on a scalar mappable and colorbar_extend is set to false, colorbar_extend is picked up by colorbar creation as the default value for the extend keyword in the constructor of matplotlib.colorbar.Colorbar.
- is_gray(self): Returns a boolean value to check if the plt is gray.
- reversed(self, name=None): It is used to make a reversed instance of Colormap. This function is not implemented for the base class. It has a single parameter ie, name that is optional and and accepts a string name for the reversed colormap. If set to None the becomes the name of the parent colormap + “r”.
- set_bad(self, color=’k’, alpha=None): It sets color that is to be used for masked values.
- set_over(self, color=’k’,, alpha=None): It is used to set color to be used for high out-of-range values. It requires norm.clip to be False.
- set_under(self, color=’k’,, alpha=None):It is used to set color to be used for low out-of-range values. It requires norm.clip to be False.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.