Matplotlib如何获取长度线
Matplotlib How to get length line
我将 Matplotlib
与 Python 2.7.6 和我的代码一起使用
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import spline
x = np.array([1,2,3])
y = np.array([1,5,15])
x_smooth = np.linspace(x.min(), x.max(), 100)
y_smooth = spline(x, y, x_smooth)
plt.plot(x_smooth, y_smooth)
plt.show()
当我 运行 它显示 image
如何获取Spline
的长度?帮帮我
import math
distance = 0
for count in range(1,len(y_smooth)):
distance += math.sqrt(math.pow(x_smooth[count]-x_smooth[count-1],2) + math.pow(y_smooth[count]-y_smooth[count-1],2))
在笛卡尔几何中,两点之间的距离计算为
p1(x,y), p2(a,b)
[p1p2] = sqrt((a-x)^2 + (b-y)^2)
我敢肯定有一种更优雅的方法可以做到这一点,可能是在一行中
我将 Matplotlib
与 Python 2.7.6 和我的代码一起使用
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import spline
x = np.array([1,2,3])
y = np.array([1,5,15])
x_smooth = np.linspace(x.min(), x.max(), 100)
y_smooth = spline(x, y, x_smooth)
plt.plot(x_smooth, y_smooth)
plt.show()
当我 运行 它显示 image
如何获取Spline
的长度?帮帮我
import math
distance = 0
for count in range(1,len(y_smooth)):
distance += math.sqrt(math.pow(x_smooth[count]-x_smooth[count-1],2) + math.pow(y_smooth[count]-y_smooth[count-1],2))
在笛卡尔几何中,两点之间的距离计算为
p1(x,y), p2(a,b)
[p1p2] = sqrt((a-x)^2 + (b-y)^2)
我敢肯定有一种更优雅的方法可以做到这一点,可能是在一行中