5

enter image description hereI 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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.