2016-04-24 19 views
1

matplotlibを使用して燭台のデータをプロットしようとしています。 1分のデータから始まり、pd.Timegrouperを使用して5分から毎日までさまざまな時間枠でグループ化しますが、プロットは毎日のデータにのみ作用します。私はpython Matplotlibの燭台プロットは、日中のデータでのみ動作します。

**Data sample:** (pandas dataframe)

data_indexed_5M = data_indexed.groupby([pd.TimeGrouper(freq=pd.offsets.Minute('5'))]).agg({'<LOW>': lambda s: s.min(), 
            '<HIGH>': lambda s: s.max(), 
            '<OPEN>': lambda s: s[0], 
            '<CLOSE>': lambda s: s[-1]}) 

ata_indexed_Daily = data_indexed.groupby([pd.TimeGrouper(freq='D')]).agg({'<LOW>': lambda s: s.min(), 
            '<HIGH>': lambda s: s.max(), 
            '<OPEN>': lambda s: s[0], 
            '<CLOSE>': lambda s: s[-1]}) 

data_indexed_Daily['Date2'] = data_indexed_Daily['dateTime'].apply(lambda d: mdates.date2num(d.to_pydatetime())) 
data_indexed_Daily = data_indexed_Daily.set_index('dateTime') 

data_indexed_5M['Date2'] = data_indexed_5M['dateTime'].apply(lambda d: mdates.date2num(d.to_pydatetime())) 
data_indexed_5M = data_indexed_5M.set_index('dateTime') 


def plotWithMatplot(dataevento): 
    deltatime = timedelta(minutes=100*5) #...(days=100) for daily plot 

    pre_data = dataevento - deltatime 
    post_data= dataevento + deltatime 

    data_slice = data_indexed_5M.loc[pre_data:post_data] #data_indexed_Daily --> for daily plot 

    tuples = [tuple(x) for x in  data_slice[['Date2','<OPEN>','<HIGH>','<LOW>','<CLOSE>']].values] 

    fig, ax = plt.subplots() 
    ax.xaxis_date() 
    ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y-%m-%d %H:%M:"))  

    plt.xticks(rotation=45) 
    plt.xlabel("Date") 
    plt.ylabel("Price") 
    plt.title("EURUSD 5M") 
    candlestick_ohlc(ax, tuples, width=.6, colorup='g', alpha =.4); 

    plt.show() 

しかし、私は毎日5分で同じイベント(他の日中の時間枠をotの)をプロットするとき:あなたは1分間のデータのサンプルを見ることができます私が使用しています次の結果を得る:

デイリー(良い結果):

enter image description here

日中(悪い結果):

enter image description here

+0

可能な解決策は[こちら]見つけることができます(http://stackoverflow.com/questions/36846032/matplotlib-candlestick-intraday-チャート - ワン - ビッグブロブ#): – jcsun

答えて

1

candlestick_ohlcに文書化されていないwidth引数が鍵となりそうです。それぞれのデータポイント間に1日の割合で掛けます。あなたのデータは分単位であるので、これは実行する必要があります。リンクは明らかではないものの

candlestick_ohlc(ax, tuples, width=.6/(24*60), colorup='g', alpha =.4); 

注これは、よくある質問であることが判明しました。参照:

+0

非常に有用な、ありがとう! – jcsun

関連する問題