2017-06-04 7 views
-2

これは私のpandas DataFrameです。私が何をしたいかパンダ:マーカー付きプロットデータフレームオブジェクト?

value action 
0  1  0 
1  2  1 
2  3  1 
3  4  1 
4  3  0 
5  2  1 
6  5  0 

action=1場合xaction=0かのoとしてマークvalueです。

ので、プロットマーカーは次のようにする必要があります: o x x x o x o

しかし、これを行う方法が分からない...

あなたの助けが必要。ありがとう。

答えて

1

次のアプローチを考えてみましょう:

plt.plot(df.index, df.value, '-X', markevery=df.index[df.action==1].tolist()) 
plt.plot(df.index, df.value, '-o', markevery=df.index[df.action==0].tolist()) 

結果:

enter image description here

代替ソリューション:

plt.plot(df.index, df.value, '-') 
plt.scatter(df.index[df.action==0], df.loc[df.action==0, 'value'], 
      marker='o', s=100, c='green') 
plt.scatter(df.index[df.action==1], df.loc[df.action==1, 'value'], 
      marker='x', s=100, c='red') 

結果:

enter image description here

1

フィルタリングされたデータフレームをプロットすることができます。つまり、アクション0とアクション1の2つのデータフレームを作成することができます。次に、それぞれ個別にプロットします。

import pandas as pd 

df = pd.DataFrame({"value":[1,2,3,4,3,2,5], "action":[0,1,1,1,0,1,0]}) 
df0 = df[df["action"] == 0] 
df1 = df[df["action"] == 1] 

ax = df.reset_index().plot(x = "index", y="value", legend=False, color="gray", zorder=0) 
df0.reset_index().plot(x = "index", y="value",kind="scatter", marker="o", ax=ax) 
df1.reset_index().plot(x = "index", y="value",kind="scatter", marker="x", ax=ax) 

enter image description here

+0

おかげで、私はラインプロット上の 'marker'を追加します。どうやってやるの? – user3595632

+0

'.plot(kind =" line "、...)'でラインプロットを行うことができます。 – ImportanceOfBeingErnest

関連する問題