简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM