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.
importnumpy as np
importmatplotlib.pyplot as plt
# setup some generic data
x, y =np.mgrid[:N, :N]
Z =(np.cos(x*0.2) +np.sin(y*0.3))
Mask out the negative and positive values.
Zpos =np.ma.masked_less(Z, 0)
Zneg =np.ma.masked_greater(Z, 0)
Display data as an image, i.e., on a 2D regular raster.
Please Login to comment...