Hello Geeks! In this article, we will try to set the color range using the matplotlib Python module. Matplotlib allows us a large range of Colorbar customization. The Colorbar is simply an instance of plt.Axes. It provides a scale for number-to-color ratio based on the data in a graph. Setting a range limits the colors to a subsection, The Colorbar falsely conveys the information that the lower limit of the data is comparable to its upper limit. With the two different limits, you can control the range and legend of the Colorbar.
Requirement: Matplotlib, NumPy
For installation Matplotlib
pip install matplotlib
For installation Numpy.
pip install numpy
Let’s understand with step-wise implementation:
Import required library and set up some generic data.
Mask out the negative and positive values.
Display data as an image, i.e., on a 2D regular raster.
Plot both positive and negative values between +/- 1.2
Below is the full implementation:
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.