I am unable to plot a variable where the points are coloured by reference to an index. What I ultimately want is the line-segment of each point (connecting to the next point) to be a particular colour. I tried with both Matplotlib
and pandas
. Each method throws a different error.
Generating a trend-line:
datums = np.linspace(0,10,5)
sinned = np.sin(datums)
plt.plot(sinned)
So now we generate a new column of the labels:
sinned['labels'] = np.where((sinned < 0), 1, 2)
print(sinned)
Which generate our final dataset:
0 labels
0 0.000000 2
1 0.598472 2
2 -0.958924 1
3 0.938000 2
4 -0.544021 1
And now for the plotting attempt:
plt.plot(sinned[0], c = sinned['labels'])
Which results in the error: length of rgba sequence should be either 3 or 4
I also tried setting the labels to be the strings 'r'
or 'b'
, which didn't work either :-/