matplotlib - (x,y) graph in Python with different colours depending on y value -


this first post , new python. have .dat file 2 columns. can plot ok, want have same graph colour depends on y value.

for reason scanning whole file, reading y value , depending on y value append , corresponding x argument on new lists , plot them.

however don't same graph.

here's code.

import numpy np import numpy.random import matplotlib.pyplot plt blackx=[] blacky=[] bluex=[] bluey=[] redx=[] redy=[] x,y=np.loadtxt('input.dat',unpack=true) t,i in zip(x,y):     if i<=16966:        blacky.append(i)        blackx.append(t)     elif i>=16967 , i<=17180:          bluey.append(i)          bluex.append(i)     else:          redx.append(t)          redy.append(i)  plt.plot(blackx,blacky,'black') plt.plot(bluex,bluey,'b') plt.plot(redx,redy,'r') plt.show() 

the problem different graph 3 colours not same graph plt.plot(x,y)

any ideas?

it looks bluex appending not t, making blue portion (y,y) plot. red , black part right , blue wrong?


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -