Multiple charts in python

I want to build a curve on the image. I would only see a curve 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 the image is displayed in this range, but I do not want this. I would like to see the whole image with part of the curve. How to apply axes only on the second chart?

EDIT: I cannot use slice arrays. I am in this case (this 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 a straight line only between 25 and 35. If I remove each element from this range, I get only a point (30,30).

+4
source share
1 answer

You can simply restrict their 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)  
+2

Source: https://habr.com/ru/post/1624991/


All Articles