0

I am new to matplotlib and I need to plot on the same figure a large amount of data. My initial code is

data = np.genfromtxt('Data.csv', delimiter=',', skip_header=10,
                 skip_footer=10, names=['CSX', 'CSY'])
fig = plt.figure()
myPlot = fig.add_subplot(111)
myPlot.plot(data['CSX'], data['CSY'], color='r', label='the data')
leg = myPlot.legend()
plt.show()

The result is acceptable, I need though to have two different colors on these data, based on a third value. Could you point me to the correct direction? Thanks!

lemanou
  • 141
  • 1
  • 2
  • 8
  • What third value? You don't seem to have any third value. – Stop harming Monica Mar 27 '16 at 14:30
  • There are more values in the csv file which I can use. You could imagine a boolean just for the sake of it. – lemanou Mar 27 '16 at 14:32
  • What do you mean with a third value? Do you want the lines to change color depending on the third value, or do you want to base the entire line color on a single value? – Chiel Mar 27 '16 at 14:41
  • So the idea is that it should be 1 plot with continuous lines as it is now, however the X,Y coordinate for the (let's say) csv variable being TRUE should be blue and the next X,Y should be red if the variable is FALSE. – lemanou Mar 27 '16 at 15:59

1 Answers1

0

Filter your data into 2 or more sets based on some value/condition and just call plot for each set of data with different colour values.

Steve Barnes
  • 27,618
  • 6
  • 63
  • 73
  • This only works if two lines are desired, if one needs a line that changes color based on the third value, a different approach is desired. – Chiel Mar 27 '16 at 14:53
  • I already tried separating the data in two lists based on the third variable and then plotting the 2 lists together but as Chiel mentioned I got two different lines(one blue and one red), which is not the desired output. – lemanou Mar 27 '16 at 16:01
  • Sorry, requirement to have 1 line with different colours added after this answer. – Steve Barnes Mar 27 '16 at 17:32