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

matplotlib, python

Solution

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()

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

Problem

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?

Original source