2015-11-21 50 views
-1

我想打開Excel中的內容兩列「時間和G」在Java中(也試圖用python),並繪製G Vs時間之間的圖形的Excel文件。並找出G最少在什麼時候最多爲&。請幫幫我!!!陰謀圖並找到最大值

+0

歡迎計算器。這個問題太廣泛了,請考慮通過添加代碼來證明你陷入困境。您可以使用[Apache POI](http://poi.apache.org/)解析java中的excel文件,並使用像[JfreeChart](http://www.jfree.org/jfreechart/)這樣的庫來生成圖形 – vsnyc

回答

0

你似乎沒有太多的編程經驗,所以我試着創建一個小例子。你說你想從Excel中獲取數據,因爲我不知道如何讀取python中的excel我假設你可以爲你的值創建一個csv文件。

import matplotlib 
import matplotlib.pyplot as plt 
from datetime import datetime 

with open("pathtoyourfiel/data.csv") as f: 
    #read file to a list of lines 
    content = f.readlines() 

    #split each line at "," 
    data = [line.split(",") for line in content] 
    #convert date string to datetime (assuming format is correct) 
    dateStrings = [datetime.strptime(d[0], "%d %b %Y") for d in data] 
    #convert datetime to matplotlib.date 
    dates = matplotlib.dates.date2num(dateStrings) 

    #extract G value from split list, cast to int 
    g = [int(d[1]) for d in data] 

    #get max and min 
    maxValue = max(g) 
    minValue = min(g) 
    #get the date at the index of max/min 
    maxDate = dateStrings[g.index(maxValue)] 
    minDate = dateStrings[g.index(minValue)] 

    #set formatter for the date on the x axis 
    plt.gca().xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%m/%d/%Y')) 
    plt.plot(dates, g) 
    plt.show() 

在我的數據是這樣的:
6月15日2015,14
7月24日2015,1
10月30日2015,5

Result

+0

謝謝Aracurunir,我現在就試試這個! – subodh