Posts: 10
Threads: 3
Joined: Sep 2019
I have these two curves. How could I plot a segment (and the number) whitch rapresent the distance between them (5 in this case) in the same graph?
1 2 3 4 5 6 7 8 9 |
import matplotlib.pyplot as plt
X_ev = [ 0 , 1 , 2 , 3 ]
Y1_ev = [ 10 , 15 , 20 , 25 ]
Y2_ev = [ 2 , 10 , 10 , 15 ]
plt.plot(X_ev,Y1_ev, 'g' , label = 'Curve 1' )
plt.plot(X_ev,Y2_ev, 'r' , label = 'Curve 2' )
plt.legend(numpoints = 3 )
plt.show()
|
Posts: 12,036
Threads: 486
Joined: Sep 2016
Oct-18-2019, 09:34 AM
(This post was last modified: Oct-18-2019, 09:34 AM by Larz60+.)
if looking for Euclidean distance between,
1 2 3 4 5 6 7 |
import numpy
import matplotlib.pyplot as plt
X_ev = [ 0 , 1 , 2 , 3 ]
Y1_ev = [ 10 , 15 , 20 , 25 ]
Y2_ev = [ 2 , 10 , 10 , 15 ]
dist = numpy.linalg.norm(Y1_ev - Y2_ev)
|
untested, but I think this is correct
Posts: 10
Threads: 3
Joined: Sep 2019
Sorry, I didn't explain myself well.
My aim is to draw the minimum distance between the points in the plot and not the curves.
I'd like to plot the line (length = SEGMENT) which links two points of different curves.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import matplotlib.pyplot as plt
import numpy as np
X_ev = np.array([ 0 , 1 , 2 , 3 ])
Y1_ev = np.array([ 10 , 15 , 20 , 25 ])
Y2_ev = np.array([ 2 , 10 , 10 , 15 ])
plt.plot(X_ev,Y1_ev, 'g' , label = 'Curve 1' )
plt.plot(X_ev,Y2_ev, 'r' , label = 'Curve 2' )
SEGMENT = min (Y1_ev - Y2_ev)
print ( 'SEGMENT' )
print (SEGMENT)
plt.legend(numpoints = 3 )
plt.show()
|
Posts: 12,036
Threads: 486
Joined: Sep 2016
Oct-18-2019, 03:32 PM
(This post was last modified: Oct-18-2019, 03:33 PM by Larz60+.)
This?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import matplotlib.pyplot as plt
import numpy as np
def list_diff(l1, l2):
new_list = []
for n, item in enumerate (l1):
new_list.append(item - l2[n])
return new_list
X_ev = np.array([ 0 , 1 , 2 , 3 ])
Y1_ev = np.array([ 10 , 15 , 20 , 25 ])
Y2_ev = np.array([ 2 , 10 , 10 , 15 ])
print ( f "distance between points: {list_diff(Y1_ev, Y2_ev)}" )
plt.plot(X_ev,Y1_ev, 'g' , label = 'Curve 1' )
plt.plot(X_ev,Y2_ev, 'r' , label = 'Curve 2' )
SEGMENT = min (Y1_ev - Y2_ev)
print ( 'SEGMENT' )
print (SEGMENT)
plt.legend(numpoints = 3 )
plt.show()
|
Posts: 10
Threads: 3
Joined: Sep 2019
No, I'd like to have this (attachment)
Attached Files
Thumbnail(s)
Posts: 12,036
Threads: 486
Joined: Sep 2016
Posts: 2,128
Threads: 11
Joined: May 2017
|