2017-08-04 38 views
0

我有在格式幾行的文件:繪製值

  • 值1 vlaue2值3
  • 值1 vlaue2值3
  • 值1 vlaue2值3
  • value1 vlaue2 value3

我希望在一張圖中繪製這個文件,使得每行的x軸值來自value1到value2的y軸值爲value3。 如何在python中使用matplotlib來做到這一點?

我是新來的python,想不到如何開始呢?

+0

那你試試?你讀過'matplotlib'文檔嗎? – Laszlowaty

回答

0

我不想爲您編寫代碼,但我認爲一個小小的試用版可以幫助我們瞭解您在尋找什麼。給定輸入值是否接近您想要獲得的結果?

import matplotlib.pyplot as plt 

values = [ 
      [0,3,2], 
      [3,8,5], 
      [8,12,4], 
      [12,18,3] 
     ] 
y = list() 
x = list() 
for inter in values : 
    y+=range(inter[0], inter[1]) 
    for x_val in range(inter[0], inter[1]) : 
     x.append(inter[2]) 
print x 
print y 
plt.figure(1) 
plt.plot(y,x) 
plt.show() 

Results plot

+0

是的,這是有效的。謝謝! – RaKo