Alessandro
Alessandro

Reputation: 794

Multiple plots on python

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).

Upvotes: 4

Views: 139

Answers (1)

B. M.
B. M.

Reputation: 18668

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)  

Upvotes: 2

Related Questions