问题描述
我正在尝试组合基本颜色(青色和黄色以获得绿色)。 这是我的代码:
import matplotlib.pyplot as plt
x = [1]
y = [1]
x2 = [2]
y2 = [1]
sizes = 150000
opacity=0.5
plt.scatter(x,y,s=sizes,alpha=opacity,color='yellow')
plt.scatter(x2,y2,color='cyan')
plt.show()
但是获得的颜色是褪色的。我想获得强烈的颜色以获得更明显的颜色差异,就像右图中的这个页面:https://en.wikipedia.org/wiki/Subtractive_color
这是我的糟糕结果,颜色之间的差异很小:
解决方法
一种方法是使用 RGB 矩阵。
浮点值介于 0 和 1 之间的 RGB 矩阵的乘积是它们颜色的减法和。
import matplotlib.pyplot as plt
import numpy as np
x = np.ones((1000,1000,3)) # Big white square
y = np.ones((1000,3)) # Another big white square of the same size as x
x[200: 600,200: 600] = (1,1,0) # Smaller yellow square in x
y[400: 800,400: 800] = (0,1) # Smaller cyan square in y
z = x * y # The product of RGB matrices is their subtractive sum
plt.imshow(z)
plt.show()