2016-03-31 54 views

回答

1

演示代碼

import numpy as np 
import matplotlib.pyplot as plt 
import random 
import pickle 


#Y Axis : Generate 1000 random numbers 
yAxisNumbers = np.random.uniform(1,100,1000) 

#Save numbers to a file for demo purpose 
with open('numpyData.txt', 'wb') as myFile: 
    pickle.dump(yAxisNumbers,myFile) 


#X Axis :Generate 1000 random numbers 
xNumbers = [ x for x in range(1000)] 

#Load file data to a list 
with open('numpyData.txt', 'rb') as aFile: 
    yNumbers = pickle.load(aFile) 

#Plot and label Graph 
plt.plot(xNumbers,yNumbers) 
plt.ylabel("Random Float Numbers") 
plt.xlabel("Number Count") 
plt.title("ECG Graph") 
plt.show() 

enter image description here

+0

請問這個答案在我的答案改善,因爲它涉及到的相關細節(正從一個文件Y數據和在基於1的增量x軸上繪圖? –

+0

我更新了代碼以從文件加載數據[猜測錯過了前面的部分]。M y代碼包含所有需求的端到端,即從一個文件加載浮點值到增量繪製,以顯示用戶需要的圖形。它提供了完整的感覺,用戶可以通過簡單地複製代碼來進行測試,而不是進行任何更改/修改 –

+0

您的代碼(更新後)具有所有要求*加上*一堆額外的東西,這些東西不是回答問題所必需的。當問題發佈後,我的答案已經具備了一切必要... –

0
import numpy as np 
import pylab as p 

aa=np.loadtxt('....your file ....') 
x,y= aa.T # transpose data into 2 columns, assuming you have 2 columns 
p.plot(x,y) 
p.show() 
1

下面是基於所提供的少量細節的最小答案。

import numpy as np 
import matplotlib.pyplot as plt 
plt.ion() 

Y = np.loadtxt(filename, other needed options) 
plt.plot(np.arange(len(Y))+1,Y)