我需要从颜色映射中查找任意数字的RGB值。你知道吗
假设我有一个颜色映射'spring'
from matplotlib import cm
c = cm.get_cmap('spring')
现在假设我有一个从0
到1
的值,我想从c
中提取RGB值
import numpy as np
np.random.seed([3, 1415])
v = np.random.rand(1)
v
0.4449393091533107
如何将其映射到相应的RGB?你知道吗
如果我看
c._segmentdata
{'blue': ((0.0, 1.0, 1.0), (1.0, 0.0, 0.0)),
'green': ((0.0, 0.0, 0.0), (1.0, 1.0, 1.0)),
'red': ((0.0, 1.0, 1.0), (1.0, 1.0, 1.0))}
。。。我不知该怎么办。你知道吗
我查过这个链接https://matplotlib.org/users/colormapnorms.html
但这告诉我如何对整个二维矩阵进行处理。你知道吗
除非我误解了你的要求,否则你可以这样做:
这将为您提供以下
RGBA
数组:因此,如果只需要
RGB
,可以根据需要对其进行索引:更多信息请参见docs
相关问题 更多 >
编程相关推荐