2017-08-02 10 views
0

独自のオリジナルデータフレームのアウトライアを排除する6種類のデータフレームを作成しました。今、私は、同じグラフ上で異常値を除去するすべてのデータフレームをプロットしようとしています。複数のパンダデータフレームを1つのグラフにプロットする

これは、各データフレームに異常値を排除し、私のコードです:私はコメントnewdf.plot()を削除した場合、私は別にグラフのすべてをプロットすることができるようになります

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 
plt.style.use("ggplot") 

#---Original DataFrame 
x = (g[0].time[:27236]) 
y = (g[0].data.f[:27236]) 
df = pd.DataFrame({'Time': x, 'Data': y}) 

#----Removes the outliers in a given DataFrame and plots a graph 
newdf = df.copy() 
newdf = df[~df.groupby('Data').transform(lambda x: abs(x-x.mean()) > 1.96*x.std()).values] 
#newdf.plot('Time', 'Data') 

#---Original DataFrame 
x = (q[0].time[:47374]) 
y = (q[0].data.f[:47374]) 
df = pd.DataFrame({'Time': x, 'Data': y}) 

#----Removes the outliers in a given DataFrame and plots a graph 
newdf = df.copy() 
newdf2 = df[~df.groupby('Data').transform(lambda x: abs(x-x.mean()) > 1.96*x.std()).values] 
#newdf2.plot('Time', 'Data') 

#---Original DataFrame 
x = (w[0].time[:25504]) 
y = (w[0].data.f[:25504]) 
df = pd.DataFrame({'Time': x, 'Data': y}) 

#----Removes the outliers in a given DataFrame and plots a graph 
newdf = df.copy() 
newdf3 = df[~df.groupby('Data').transform(lambda x: abs(x-x.mean()) > 1.96*x.std()).values] 
#newdf3.plot('Time', 'Data') 

#---Original DataFrame 
x = (e[0].time[:47172]) 
y = (e[0].data.f[:47172]) 
df = pd.DataFrame({'Time': x, 'Data': y}) 

#----Removes the outliers in a given DataFrame and plots a graph 
newdf = df.copy() 
newdf4 = df[~df.groupby('Data').transform(lambda x: abs(x-x.mean()) > 1.96*x.std()).values] 
#newdf4.plot('Time', 'Data') 

#---Original DataFrame 
x = (r[0].time[:21317]) 
y = (r[0].data.f[:21317]) 
df = pd.DataFrame({'Time': x, 'Data': y}) 

#----Removes the outliers in a given DataFrame and plots a graph 
newdf = df.copy() 
newdf5 = df[~df.groupby('Data').transform(lambda x: abs(x-x.mean()) > 1.96*x.std()).values] 
#newdf5.plot('Time', 'Data') 

#---Original DataFrame 
x = (t[0].time[:47211]) 
y = (t[0].data.f[:47211]) 
df = pd.DataFrame({'Time': x, 'Data': y}) 

#----Removes the outliers in a given DataFrame and plots a graph 
newdf = df.copy() 
newdf6 = df[~df.groupby('Data').transform(lambda x: abs(x-x.mean()) > 1.96*x.std()).values] 
#newdf6.plot('Time', 'Data') 

が、私は1つのグラフ上にすべてをしたいです。

はい、私はすでにhttp://matplotlib.org/examples/pylab_examples/subplots_demo.html を読んでいますが、そのリンクには1つのグラフに複数のプロットの例がありません。

これも読んでいます:http://pandas-docs.github.io/pandas-docs-travis/visualization.html本当に素晴らしい情報がありますが、1つのグラフに複数のプロットがある例では同じデータフレームが使用されています。私は6つの別々のデータフレームを持っています。 私の問題の1つの解決策は、すべてのデータフレームを同じExcelファイルに書き込んでからExcelからプロットすることだと思っていましたが、それは過剰であると思われ、このデータをExcelファイルに保存する必要はありません。

私の質問はこれです: 複数のパンダのデータフレームを同じグラフにプロットするにはどうすればよいですか?グラフは、多かれ少なかれあなたがpandas.dataframe.plotでaxパラメータを使用する必要が

答えて

0

何か不足していますか? 通常、複数のデータフレームでこれを行います。

fig = plt.figure() 

for frame in [newdf, newdf2, newdf3, newdf4, newdf5]: 
    plt.plot(frame['Time'], frame['Data']) 

plt.xlim(0,18000) 
plt.ylim(0,30) 
plt.show() 
1

ようになるはずです何スコットのアドバイス enter image description here

enter image description here

を次後

マイグラフ。その上のハンドルをつかむために最初df.plot上

使用すると、軸:

ax = newdf.plot() 

その後のプロット上の斧パラメータを使用します。

newdf2.plot(ax=ax) 
... 
newdf5.plot(ax=ax) 
+0

そのような仕組みです。それは私のプロットをすべて1つのグラフにしてしまったが、すべてのデータが混乱してしまった。私は自分のデータを元の質問のように見えるようにしたものをjpgで投稿します。 –

+0

すべてのデータは同じスケールですか?おそらく、複数のプロットや少なくとも複数のy軸を使用することは理にかなっています。 –

+0

2番目のjpgでは、データがx軸とy軸の両方を共有しているように見えます。だから、私が望むのは、ここの例のようなプロットを分ける必要はありません。[リンク](http://matplotlib.org/examples/pylab_examples/subplots_demo.html)3つの異なるプロットがx/y軸を含む。このデータのすべてが同じパラメータの下にあるので、複数のプロットは私のためには機能しませんでした。 –