I have data which I have to plot
X = [0,1,2,3,4,5] Y = [6,7,8,9,10,11,12,13,14,15]
X belongs to class1, so I would want them to be plotted green in color and Y belongs to class2, so I would want them to be plotted blue in color.
What I did was,
import pylab as pl
pl.plot(X,'go')
pl.plot(Y,'bo')
pl.show()
But this is plotting X against Y. All I want to display in my graph is just the points X and Y in green and blue colors respectively.
How can I accomplish this?
It doesn't plot X against Y, if only because X and Y are not the same length. Let's say x
is the variable (horizontal axis) and y
the result (vertical axis). Normally you write pl.plot(x,y)
, where x
and y
are lists of the same length. If you give only one list, it assumes you only gave y
and matplotlib will make an x-axis for you, something like this:
import pylab as pl
y1 = [0,1,2,3,4,5]
y2 = [6,7,8,9,10,11,12,13,14,15]
x1 = range(len(y1))
x2 = range(len(y2))
pl.plot(x1, y1,'go')
pl.plot(x2, y2,'bo')
pl.show()
So I think in your case you should define the x-axis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With