3

I have a 2-D array and I need to plot columns x and y but only within a certain range of x. I know how to plot using the index but I need to specify the value of x. I have a few of those arrays so I am trying to find a way to do that without having to look at each one of them individually.

Here is an example:

array([[  4.40148390e+03,   1.13200000e+00],
       [  4.40248390e+03,   1.12200000e+00],
       [  4.40348440e+03,   1.11600000e+00],
       [  4.40448440e+03,   1.10600000e+00],
       [  4.40548490e+03,   1.09200000e+00],
       [  4.40648490e+03,   1.07700000e+00],
       [  4.40748540e+03,   1.08700000e+00],
       [  4.40848540e+03,   1.09400000e+00],
       [  4.40948580e+03,   1.10200000e+00],
       [  4.41048580e+03,   1.09500000e+00],
       [  4.41148630e+03,   1.12000000e+00]])

So let's say I only need 4402 < x < 4410 but I don't know the index. Can I put something like: plot(x, y, where(4402 < x < 4410))?

I feel like there is something obvious that I am missing here :p

2
  • 1
    a[(a[:,0]>4402)&(a[:,0]<4410)] Commented Apr 14, 2013 at 1:44
  • @mtadd Can you please post that as an answer (and maybe add some text explaining it) Commented Apr 14, 2013 at 2:40

1 Answer 1

5

You could use matplotlib to set limits on your x-axis so as not to display all the points in your data series. However, we can filter your numpy array above as follows:

a = array([[ .... ]])
x = a[:,0]
y = a[:,1]

filter = (x>4402)&(x<4410)

plot(x[filter],y[filter])
Sign up to request clarification or add additional context in comments.

1 Comment

If this answer is accepted, this question should be tagged numpy.

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.