DGraham
DGraham

Reputation: 715

Color on a scatter graph Python Matplotlib

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.

Upvotes: 1

Views: 3906

Answers (2)

Benjamin Bannier
Benjamin Bannier

Reputation: 58594

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

Example

Upvotes: 3

Jdog
Jdog

Reputation: 10721

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.

Upvotes: 1

Related Questions