2016-03-15 76 views
0

我有一个简单hist2d其中我想0之间的密度(彩条)范围为1疑惑 - matplotlib

这是我的代码:

plt.hist2d(x_values, y_values, bins=50, normed=True) 
plt.colorbar(norm=colors.NoNorm) 

那么,它如何设置0.0到1.0之间的颜色条值。例如:[0.0,0.2,0.4,06,0.8,1.0]

你能帮助我吗? 谢谢!

enter image description here

回答

2

的号召加入vmin=0, vmax=1plt.hist2d

import matplotlib.pyplot as plt 
import matplotlib.colors as mcolors 
import numpy as np 
np.random.seed(2016) 

N = 10**3 
x_values = (np.random.random(size=N))*15 
y_values = np.random.random(size=N) 
plt.hist2d(x_values, y_values, bins=50, normed=True, vmin=0, vmax=1) 
plt.colorbar(norm=mcolors.NoNorm) 
plt.show() 

的彩条总是本身关联到一个单一的着色艺术家。当没有艺术家提供时(如mappable),使用当前着名艺术家。在这种情况下,它是由plt.hist2d创建的艺术家。该艺术家的vminvmaxaffect the range of values displayed by the colorbar

enter image description here