Python:将不断变化的浮点值绘制为颜色

时间:2018-07-04 06:09:06

标签: python matplotlib

我有三种颜色的元组的列表:

v = ([0.16091847477176702, 0.4337815920028113, 0.40529993322542174)
(0.15019057645364922, 0.40486281920262385, 0.44494660434372696)
(0.14017787135673926, 0.44453863125578225, 0.4152834973874785)
(0.13083267993295664, 0.41490272250539673, 0.45426459756164661)
(0.17697859494133705, 0.36303988219222216, 0.45998152286644078)
(0.16591743275750348, 0.40284988955520828, 0.43123267768728824)
(0.16591743275750348, 0.40284988955520828, 0.43123267768728824)
(0.16591743275750348, 0.40284988955520828, 0.43123267768728824)
(0.15406618756053894, 0.37407489744412198, 0.47185891499533911)
(0.20019069588580043, 0.32419824445157241, 0.47561105966262723)
(0.20019069588580043, 0.32419824445157241, 0.47561105966262723)
(0.17349860310102702, 0.34763847852469609, 0.47886291837427691)
(0.16193202956095856, 0.39112924662304965, 0.44693872381599176)]

元组中的每个值我通常都将其解释为颜色(例如:黄色,红色,蓝色),因此每个元组一起给我一个颜色(作为第一个,第二个和第三个的混合) 。是否可以使用matplotlib绘制颜色变化?我最初的想法是使用RGB,但是RGB接受整数,这些数字的精度非常重要。有人有什么建议吗?

1 个答案:

答案 0 :(得分:0)

浮点数介于0和1之间是matplotlib中rgb的良好值。这是一个小例子

import numpy as np
import matplotlib.pyplot as plt

v = [(0.16091847477176702, 0.4337815920028113, 0.40529993322542174),
(0.15019057645364922, 0.40486281920262385, 0.44494660434372696),
(0.14017787135673926, 0.44453863125578225, 0.4152834973874785),
(0.13083267993295664, 0.41490272250539673, 0.45426459756164661),
(0.17697859494133705, 0.36303988219222216, 0.45998152286644078),
(0.16591743275750348, 0.40284988955520828, 0.43123267768728824),
(0.16591743275750348, 0.40284988955520828, 0.43123267768728824),
(0.16591743275750348, 0.40284988955520828, 0.43123267768728824),
(0.15406618756053894, 0.37407489744412198, 0.47185891499533911),
(0.20019069588580043, 0.32419824445157241, 0.47561105966262723),
(0.20019069588580043, 0.32419824445157241, 0.47561105966262723),
(0.17349860310102702, 0.34763847852469609, 0.47886291837427691),
(0.16193202956095856, 0.39112924662304965, 0.44693872381599176)]

y = np.arange(len(v))
for i in range(len(v)):
    plt.plot(y[i], 0, marker='o', ls='', c=v[i], markersize=20)

plt.show()

和结果:

enter image description here

它很微妙,但是有效