简体   繁体   中英

Python Matplotlib scatter plot: specify color points depending on difference between X & Y:

I want to color points uniquely only if there is a difference between the x & y values (eg abs(x - y) > 10).

How can I do that?

num = 1000
x = np.linspace(0,100, num = num)
y = np.random.normal(size = num)

plt.scatter(x, y, c='r', edgecolors='black')
plt.gca().spines['right'].set_color('none')
plt.gca().spines['top'].set_color('none')
plt.show()

You can create a color vector based on the cut off rule such as

plt.scatter(x, y, c=np.where(np.abs(xy)>10, 'g', 'b'), edgecolors='black')

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM