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?
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,022
Threads: 484
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,
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.
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,022
Threads: 484
Joined: Sep 2016
Oct-18-2019, 03:32 PM
(This post was last modified: Oct-18-2019, 03:33 PM by Larz60+.)
This?
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,022
Threads: 484
Joined: Sep 2016
Posts: 2,122
Threads: 10
Joined: May 2017
|