[英]Generate heatmap rgba values python
I need to generate a list of color representation of numbers (kind of like a heatmap), but just the rgba values.我需要生成数字的颜色表示列表(有点像热图),但只是 rgba 值。 Something that gets as input a list of numbers and return a set of rgba values representing these numbers.将数字列表作为输入并返回一组表示这些数字的 rgba 值的东西。 Is there a module that do this in python? python 中是否有执行此操作的模块?
thanks谢谢
as a starting point, you could do something along these lines to make a function that returns an rgba for an input value, based on a predefined scale for the colormap:作为起点,您可以按照这些思路做一些事情来制作一个 function,它根据颜色图的预定义比例返回一个 rgba 作为输入值:
from matplotlib.colors import cm
def get_rgba(value, limits, cmap):
fac = (value-limits[0]) / (limits[1]-limits[0])
return cmap(fac)
cmap = cm.get_cmap('jet')
limits = [0,10]
value = 5.292
print(get_rgba(value, limits, cmap))
output: output:
(0.5787476280834913, 1.0, 0.38899430740037955, 1.0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.