If you want different labels, you need different plots.
Filter your data according to your formula.
In this case I took values which are more than 1.5 standard deviations away from the mean. In case you don't know, in numpy
you can use boolean masks to index arrays and only take elemets where the mask is True
. You can also easily flip the mask with the complement operator ~
.
import matplotlib.pyplot as plt
import numpy as np
k=np.array([12,11,12,12,20,10,12,0,12,10,11])
x2=np.arange(1,12,1)
# find out which parameters are more than 1.5*std away from mean
warning = np.abs(k-np.mean(k)) > 1.5*np.std(k)
# enable drawing of multiple graphs on one plot
plt.hold(True)
# draw some lines behind the scatter plots (using zorder)
plt.plot(x2, k, c='black', zorder=-1)
# scatter valid (not warning) points in blue (c='b')
plt.scatter(x2[~warning], k[~warning], label='signal', c='b')
# scatter warning points in red (c='r')
plt.scatter(x2[warning], k[warning], label='warning', c='r')
# draw the legend
plt.legend()
# show the figure
plt.show()
This is what you get:
