python - 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
这是我的糟糕结果,颜色之间的差异很小:
解决方案
一种方法是使用 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()
推荐阅读
- python - Python 3.7 builtins.NameError
- python - 如何在python中找到字符串中子字符串的出现次数?
- python - pytorch 可以优化顺序操作(如张量流图或 JAX 的 jit)吗?
- javascript - 将初始数据从服务器传递到 React 应用程序
- spring - Spring JPA 多线程
- c# - 如何在 .NET Core 中修复(不抑制)CA1303(不将文字字符串作为本地化参数传递)
- ruby - 什么参数应该传递给其他方法
- java - 使用 Flink 监控新文件的目录以获取数据流
- c++ - 使用从 1 到 N 模板参数的数字初始化 std 数组
- elasticsearch - 哪个节点应该用于 ElasticSearch 的连接?