4

I want to plot a curve on an image. I would to see the curve only in a certain range. So:

plt.figure()
plt.imshow(img)
plt.plot(x, my_curve)
plt.axis([0, X, Y, 0])

But in this way also the image is showed in that range, but I don't want this. I would like to see the whole image with a portion of the curve. How can apply the axes only on the second plot?

EDIT: I can't use a slice of the arrays. I am in this case (it is an example):

x        = [0 0 0 10 10 10 30 30 30 40 40 40]
my_curve = [0 0 0 10 10 10 30 30 30 40 40 40]

Well I need to see the straight line only between 25 and 35. If I delete each element out of such range, I obtain only the point (30,30).

4
  • Have you tried plotting a slice of the x and my_curve in plt.plot(x, my_curve) to something like plt.plot(x[:X], my_curve[:X])? Commented Jan 19, 2016 at 16:20
  • I can't do this. my_curve derives by an interpolation. And considering only my_curve[0:X] I lose significant information (I can't reproduce the line) Commented Jan 19, 2016 at 16:35
  • This changes things slightly -- you could search for the index of X in x (we'll call it X_idx) and then do plt.plot(x[:X_idx], my_curve[:X_idx]). Commented Jan 19, 2016 at 16:39
  • Good answer, but it does not work. See my edit. Commented Jan 19, 2016 at 16:42

1 Answer 1

2

You can just restrict your data : plt.plot(x[0:X], my_curve[0:X]).

EDIT

If your data is sparse, you can interpolate it :

x2=linspace(x[0],x[-1],1000)[0:X]
my_curve2=np.interp(x2,x,my_curve)
plt.plot(x2, my_curve2)  
Sign up to request clarification or add additional context in comments.

1 Comment

I can't, because my_curve is an interpolated data.

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.