I'm plotting a scatterplot using matplotlib in python. I want to color the points based on some function, like so:
import matplotlib.pyplot as plt
def color(x, y):
# based on some rules, return a color
if(condition):
return 'red'
else:
return 'blue'
plt.scatter(index, data) #c= something?
I'm aware of the matplotlib.from_levels_and_colors
function, but the problem is that the mapping isn't based on levels of the values on the x or y axes. There's a third value associated with each data point that is calculated by the function, and that's what I want to color the dots based on.
Is there a way to do this?