Reputation: 33
I've got a scatter graph created from data I'm using, with plt.plot(), and wondered if there is an easy way to colour the points depending on where they are on the x axis? As in, if they lie between x0 and x1 make them green, x1 and x2 make them blue etc. Any help? Cheers
Upvotes: 1
Views: 482
Reputation: 49032
You could use plt.scatter
:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style("white")
x, y = np.random.multivariate_normal([0, 0], [(1, .5), (.5, 1)], 200).T
c = np.where(x < 0, "#27ae60", "#2980b9")
plt.scatter(x, y, 30, c)
sns.despine()
Upvotes: 3