首页 > 解决方案 > python散点图结合减色青色和黄色以获得强烈的绿色,不褪色

问题描述

我正在尝试结合基本颜色(青色和黄色以获得绿色)。这是我的代码:

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, s=sizes, alpha=opacity, color='cyan')

plt.show()

但是获得的颜色会褪色。我想获得强烈的颜色以获得颜色之间更明显的差异,就像在右边的这个页面上一样:https ://en.wikipedia.org/wiki/Subtractive_color

这是我的糟糕结果,颜色之间的差异很小:

组合的颜色,但褪色

标签: pythonmatplotlibscatter

解决方案


一种方法是使用 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, 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, 1) # Smaller cyan square in y

z = x * y # The product of RGB matrices is their subtractive sum

plt.imshow(z)
plt.show()

示例图


推荐阅读