Color on a scatter graph Python Matplotlib

ぐ巨炮叔叔 提交于 2019-12-11 06:39:55

问题


I have two variables I want to plot on a scatter graph. I want one variable to be displayed in blue and the other in red. I only just started using Python, and I am rather confused.


回答1:


scatter takes an argument color which allows you to set the point color (hard to guess).

x = linspace(0,10)
y1 = randn(50)
y2 = randn(50)+10

scatter(x, y1, color='red')
scatter(x, y2, color='blue')




回答2:


import numpy as np
import matplotlib.pyplot as plt
x = np.arange(10)
y = x
z = x*2
plt.scatter(x,y,c="r")
plt.scatter(x,z,c="b")
plt.show()

Have a read of this and the matplotlib docs in general.



来源:https://stackoverflow.com/questions/13139484/color-on-a-scatter-graph-python-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!