画一条连接两个点而不是一条直线的曲线

Mya*_*ath 5 python matplotlib

我想做这样的事情:
在此处输入图片说明

我有要点,但不知道如何绘制曲线而不是直线。

谢谢。

Joe*_*elt 10

对于对这个问题感兴趣的人,我按照马修的建议提出了这个实现:

def hanging_line(point1, point2):
    import numpy as np

    a = (point2[1] - point1[1])/(np.cosh(point2[0]) - np.cosh(point1[0]))
    b = point1[1] - a*np.cosh(point1[0])
    x = np.linspace(point1[0], point2[0], 100)
    y = a*np.cosh(x) + b

    return (x,y)
Run Code Online (Sandbox Code Playgroud)

结果如下:

import matplotlib.pyplot as plt

point1 = [0,1]
point2 = [1,2]
x,y = hanging_line(point1, point2)

plt.plot(point1[0], point1[1], 'o')
plt.plot(point2[0], point2[1], 'o')
plt.plot(x,y)
Run Code Online (Sandbox Code Playgroud)

§1