Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
592 views
in Technique[技术] by (71.8m points)

matplotlib - python scatter plot combine subtractive colors cyan and yellow to obtain strong green color, not faded

I am trying to combine basic colors (cyan and yellow to obtain green color). Here is my code:

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()

But obtained colors are faded. I would like to obtain strong colors to obtain more visible difference between colors, like on this page in the right plot: https://en.wikipedia.org/wiki/Subtractive_color

Here is my poor result, with low difference between colors:

Combined colors, but faded

question from:https://stackoverflow.com/questions/65894258/python-scatter-plot-combine-subtractive-colors-cyan-and-yellow-to-obtain-strong

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

One way to do this is working with RGB matrices.

The product of RGB matrices, with float values between 0 and 1, is the subtractive sum of their colors.

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()

Example plot


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...