2016-06-17 11 views
1

私は負荷のばらつきを視覚的に分析しようとしています。私はCSVファイルからデータを読み込み、インデックスをdatetime形式に変換しました。これはうまくいきます。データは、昼間(現在は07:00-18:00に選択されている)の関心時間で、1年間、5分ごとです。時間が重なっているパンダプロットの時報

私が解決しようとした質問の1つである選択した時間(pandas timeseries between_datetime function?)を使用して、時系列データを順次プロットすることができます。

私が今やっていることは、日中のデータを固定(昼間)のx軸でプロットして、1日あたりのデータが07:00から18:00の間で実行されるようにします。年(または月)の各日はグラフ上の別の行になります。シーケンシャル時系列プロットのための私のコードの

例:

import pandas as pd 
import matplotlib.pyplot as plt 
import matplotlib 

Y13 = pd.read_csv(path + "Y13.csv") 
Y13.index = pd.to_datetime(Y13.Datetime) 
Y14 = pd.read_csv(path + "Y14.csv") 
Y14.index = pd.to_datetime(Y14.Datetime) 

fig, axes = plt.subplots(nrows=2, ncols=1, sharex=True) 
Y13.LOAD.between_time('07:00','18:00').plot(ax=axes[0]) 
Y14.LOAD.between_time('07:00','18:00').plot(ax=axes[0]) 

Y13.LOAD.between_time('07:00','18:00').diff().plot(ax=axes[1]) 
Y14.LOAD.between_time('07:00','18:00').diff().plot(ax=axes[1]) 

私はループを使用して、これをプロットすることができますが、より効率的な/神託/パンダの方法は、素晴らしいことだと仮定します。

私は時系列データをプロットするのに間違っているのですか、それとも他に大きなギャップがありますか?

おかげ

答えて

2

pandas.plotは何が必要かもしれない引数subplotsを持っています。お役に立てれば。

Pandas Visualization - Subplots

In[1]: import pandas as pd 

In[2]: import numpy as np 

In[3]: datapoints = 365 * 24 * 12 

In[4]: data = pd.DataFrame({"Data": np.random.randn(datapoints)}, index=pd.date_range(start="2015-01-01", freq="5min", periods=datapoints)) 

In[5]: data = data.between_time("07:00", "18:00") 

In[6]: data["Date"] = data.index.date 

In[7]: data["Time"] = data.index.time 

In[8]: data[:4] 
Out[8]: 
         Data  Date  Time 
2015-01-01 07:00:00 0.890659 2015-01-01 07:00:00 
2015-01-01 07:05:00 -0.643869 2015-01-01 07:05:00 
2015-01-01 07:10:00 0.267501 2015-01-01 07:10:00 
2015-01-01 07:15:00 0.627690 2015-01-01 07:15:00 

In[9]: data = data.pivot(index="Time", columns="Date", values="Data") 

In[10]: data.iloc[:, 0:4].plot(subplots=True) 
Out[10]: 
array([<matplotlib.axes._subplots.AxesSubplot object at 0x1213316d0>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0x1214b3e90>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0x120fa7350>, 
     <matplotlib.axes._subplots.AxesSubplot object at 0x11eb6bf10>], dtype=object) 

Chart

関連する問題