2017-10-11 34 views
-1
import matplotlib.pyplot as plt 

x = [1,2,3,4,5,6] 
y = [1,3,6,8,14,20] 

plt.plot(x,y) 

plt.show() 

输出: enter image description here如何从图表中提取点?

上述地块有不同的山坡上,我想从图中获得100多个点,任何一个可以帮助我找到了点?

回答

2

为了找到曲线上的100个点,您将不得不插入数据。一种做法是使用scipy.interpolate.interp1d,文档可以找到here

import matplotlib.pyplot as plt 
import numpy as np 
from scipy import interpolate 

x =[1,2,3,4,5,6] 
y = [1,3,6,8,14,20] 

f = interpolate.interp1d(x,y) 
xnew = np.linspace(x[0],x[-1],100) 

plt.plot(x,y,'o') 
plt.plot(xnew, f(xnew)) 

plt.show() 

为了检查是否安装了100分:

print (xnew.shape) 
print (f(xnew).shape) 
#(100,) 
#(100,) 

enter image description here

+0

谢谢您的回复! –