Python matplotlib colormap提供重复的值

Python matplotlib colormap提供重复的值,python,matplotlib,colormap,Python,Matplotlib,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) import matplotlib.pyplot as plt import numpy as np numbers = np.linspace(0,1,6) newcm

最近我用这个方法在这个颜色图上选择了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)
import matplotlib.pyplot as plt
import numpy as np

numbers = np.linspace(0,1,6)
newcm = plt.cm.Accent(numbers)
print(newcm)
通常这将返回colormap值,没有问题。现在,当我运行它时,我为
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.        ]])
所以现在事情的发展并不顺利。我也尝试过
bytes=True
,但行为是一样的。其他人是否得到了相同的结果,或者是我的matplotlib上的某个有趣设置出错了


此外,这种情况似乎特别发生在重音颜色贴图上,但不一定发生在其他颜色贴图上。

通常,颜色贴图的范围在0到1之间。在
np.linspace(0255,6)
中,除第一个之外的所有值都大于1,因此,除了该列表的第一项之外,您将获得与最大值1对应的输出

如果改为使用
numbers=np.linspace(0,1,6)
,您将从该颜色映射中获得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)
import matplotlib.pyplot as plt
import numpy as np

numbers = np.linspace(0,1,6)
newcm = plt.cm.Accent(numbers)
print(newcm)
产生

[[ 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.        ]]

通常,颜色贴图的范围介于0和1之间。在
np.linspace(0255,6)
中,除第一个之外的所有值都大于1,因此,除了该列表的第一项之外,您将获得与最大值1对应的输出

如果改为使用
numbers=np.linspace(0,1,6)
,您将从该颜色映射中获得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)
import matplotlib.pyplot as plt
import numpy as np

numbers = np.linspace(0,1,6)
newcm = plt.cm.Accent(numbers)
print(newcm)
产生

[[ 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.        ]]

是的,这是真的,唉,我想我已经试过了。我仍然有一个问题,但不是上面的问题。。。感谢这个问题也在从mpl 1.5变为2.0,以及处理离散化彩色贴图的方式……是的,这是真的,唉,我想我已经尝试过了。我仍然有一个问题,但不是上面的问题。。。感谢这个问题也正在从mpl 1.5变为2.0,以及处理离散化彩色贴图的方式。。。