关于在hist2d图中设置colorbar范围的疑问 - matplotlib

时间:2016-03-15 00:36:10

标签: python matplotlib

我有一个简单的hist2d,其中我想将密度(colorbar)的范围设置在0到1之间。

这是我的代码:

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

那么,如何将colorbar值设置在0.0到1.0之间。例如:[0.0,0.2,0.4,06,0.8,1.0]

你可以帮帮我吗? 谢谢!

enter image description here

1 个答案:

答案 0 :(得分:2)

plt.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() 的调用中:

plt.hist2d

colorbar始终将自己与一位可着色的艺术家联系在一起。如果未提供艺术家(作为mappable),则使用当前可着色艺术家。在这种情况下,它是由vmin创建的艺术家。该艺术家affect the range of values displayed by the colorbarvmax<android.support.v7.widget.Toolbar ... android:layout_height="?attr/actionBarSize" /> 值。

enter image description here