我需要在灰色的色彩地图中显示2D矩阵中的数据,但我需要将其定义为灰度,即白色和黑色不是颜色的最小值和最大值矩阵,以便不会使图像饱和。我需要的是灰度等级在20%和70%之间的灰度色彩图,灰度级之间至少有20%的差异。有什么建议么? 我正在使用matplotlib的imshow任务表单。在python色彩地图中设置颜色限制
非常感谢!
我需要在灰色的色彩地图中显示2D矩阵中的数据,但我需要将其定义为灰度,即白色和黑色不是颜色的最小值和最大值矩阵,以便不会使图像饱和。我需要的是灰度等级在20%和70%之间的灰度色彩图,灰度级之间至少有20%的差异。有什么建议么? 我正在使用matplotlib的imshow任务表单。在python色彩地图中设置颜色限制
非常感谢!
您可以通过使用您喜欢的颜色创建custom color地图,或使用imshow
中的vmin
, vmax
关键字来强制颜色栏上的大于您想要使用的范围。
你解决了你的问题吗? 我想这是你想要的,试试这个:
所有代码pylab模式:
a = np.arange(100).reshape(10,10)
#here is the image with white and black end
imshow(a,cmap=mat.cm.binary)
colorbar()
#we extract only the 0.2-->0.7 part of original colormap and make a new one
#so that the white and black end are removed
rgba_array = mat.cm.binary(np.linspace(0,1,num=10,endpoint=True))
extract_rgba_array_255 = rgba_array[2:8,0:3]
imshow(a,cmap=mat.colors.ListedColormap(extract_rgba_array_255))
colorbar()
我试过了...但在字典定义,RBG颜色必须从0.0到1.0,所以最后我仍然会有“绝对的”白色广告黑色......对吧?我尝试设置vmin = 0.2和vmax = 0.7,并且根本没有任何变化......即使在imshow参数中norm = None:我该怎么办? – manu 2012-07-29 20:13:53