Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set maximum and minimum value in the color scale of contourf ?

How can I set maximum and minimum value in the color scale of contourf of matplotlib?

I explain. I have a set of data and I want to put as maximum in the color scale the 95% percentile of the data.

I have tried in this way:

goh = colors.Normalize(0, perchi)

plt.contourf(x, y, B, norm = goh) #cmap = plt.cm.hot,

plt.colorbar()

plt.show()

but it returns to me a plot with only one color...and also the scale is monochromatic... I want the whole color scale linear but in the range (min, perchi) and not in (min, max). I want that the points between perchi and max are shown as if the y have perchi values...

How could I do?

like image 811
spec3 Avatar asked Jan 30 '14 16:01

spec3


1 Answers

to set the maximum and minimum valued you can do something like:

import matplotlib.pylab as plt
import numpy as np

# Create fake data
B = np.random.uniform(0, 10, size=(100, 100))


plt.contourf(B, vmin=2, vmax=8)
plt.colorbar()

enter image description here

The values outside the range are set to the maximum and minimum.

like image 192
Greg Avatar answered Sep 18 '22 06:09

Greg