Profile Picture

How to set Colorbar Range in matplotlib using Python

Posted By rohitbhat.intellipaat 3 Months Ago
You don't have permission to rate!
Author
Message
rohitbhat.intellipaat
rohitbhat.intellipaat
Posted 3 Months Ago
View Quick Profile
New Member

New Member (36 reputation)New Member (36 reputation)New Member (36 reputation)New Member (36 reputation)New Member (36 reputation)New Member (36 reputation)New Member (36 reputation)New Member (36 reputation)New Member (36 reputation)

Group: Forum Members
Last Active: 3 Months Ago
Posts: 1, Visits: 3
I'm pursuing the Python course and I have the following code:

import matplotlib.pyplot as pltcdict = {cdict = {  'red'  :  ( (0.0, 0.25, .25), (0.02, .59, .59), (1., 1., 1.)),  'red'  :  ( (0.0, 0.25, .25), (0.02, .59, .59), (1., 1., 1.)),  'green':  ( (0.0, 0.0, 0.0), (0.02, .45, .45), (1., .97, .97)),  'green':  ( (0.0, 0.0, 0.0), (0.02, .45, .45), (1., .97, .97)),  'blue' :  ( (0.0, 1.0, 1.0), (0.02, .75, .75), (1., 0.45, 0.45))  'blue' :  ( (0.0, 1.0, 1.0), (0.02, .75, .75), (1., 0.45, 0.45))}}cm = m.colors.LinearSegmentedColormap('my_colormap', cdict, 1024)cm = m.colors.LinearSegmentedColormap('my_colormap', cdict, 1024)plt.clf()plt.clf()plt.pcolor(X, Y, v, cmap=cm)plt.pcolor(X, Y, v, cmap=cm)plt.loglog()plt.loglog()plt.xlabel('X Axis')plt.xlabel('X Axis')plt.ylabel('Y Axis')plt.ylabel('Y Axis')plt.colorbar()plt.colorbar()plt.show()plt.show()


So this produces a graph of the values 'v' on the axes X vs Y, using the specified colormap. The X and Y axes are perfect, but the colormap spreads between the min and max of v. I would like to force the colormap to range between 0 and 1.
Edited
3 Months Ago by rohitbhat.intellipaat



Reading This Topic