[英]matplotlib colormap giving duplicated values
Recently I was using this method to basically select 6 equally values along this colormap. 最近,我使用这种方法基本上沿着该色图选择了6个相等的值。
import matplotlib.pyplot as plt
import numpy as np
ints = np.linspace(0,255,6)
ints = [int(x) for x in ints]
newcm = plt.cm.Accent(ints)
Normally this would return the colormap values no problem. 通常,这将返回颜色图值没有问题。 Now when I run this, the output I get for
newcm
is: 现在,当我运行此命令时,对于
newcm
我得到的输出是:
Out[25]:
array([[ 0.49803922, 0.78823529, 0.49803922, 1. ],
[ 0.4 , 0.4 , 0.4 , 1. ],
[ 0.4 , 0.4 , 0.4 , 1. ],
[ 0.4 , 0.4 , 0.4 , 1. ],
[ 0.4 , 0.4 , 0.4 , 1. ],
[ 0.4 , 0.4 , 0.4 , 1. ]])
So now things are not plotting right. 因此,现在情况并非正确。 I have also tried
bytes=True
but the behaviour is the same. 我也尝试过
bytes=True
但是行为是相同的。 Do others get the same result or is it some funny setting on my matplotlib that has gone awry? 其他人会得到相同的结果吗,还是我的matplotlib上的某个有趣的设置出现了问题?
Moreover - it seems this is happening in particular on the Accent colormap, but not necessarily others. 此外-似乎这在Accent颜色图上特别在发生,但不一定是其他情况。
In general, a colormap ranges between 0 and 1. In np.linspace(0,255,6)
all values except the first are larger than 1, hence you get the output corresponding to the maximum value 1 for all but the first item of that list. 通常,颜色映射的范围是0到1。在
np.linspace(0,255,6)
除第一个值之外的所有值都大于1,因此对于该列表中除第一项以外的所有值,您都获得对应于最大值1的输出。 。
If instead you use numbers = np.linspace(0,1,6)
, you will get 6 different values from that colormap. 相反,如果您使用
numbers = np.linspace(0,1,6)
,则将从该颜色图中获得6个不同的值。
import matplotlib.pyplot as plt
import numpy as np
numbers = np.linspace(0,1,6)
newcm = plt.cm.Accent(numbers)
print(newcm)
produces 产生
[[ 0.49803922 0.78823529 0.49803922 1. ]
[ 0.74509804 0.68235294 0.83137255 1. ]
[ 1. 1. 0.6 1. ]
[ 0.21960784 0.42352941 0.69019608 1. ]
[ 0.74901961 0.35686275 0.09019608 1. ]
[ 0.4 0.4 0.4 1. ]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.