2017-12-29 14 views
0

緑色のデータポイントと赤色のデータポイントの平均を持つ2つの線(赤と緑)を取得したいと考えています。私は次のコードを使用していますが、動作しません。それだけで、あなたのpinny_meanはyの単一の値であるため、これが動作していない赤平均線Pythonの平均行を上書きする

sns.set(rc={"figure.figsize": (16, 8)}) 
ax = events_all_metrics[["event_name","kambi_payback"]].plot(x="event_name", style='.',use_index=False, color ='green') 
events_all_metrics[["event_name","pinny_payback"]].plot(x="event_name",style='.', color='red', ax=ax) 
plt.tick_params(
    axis='x',   # changes apply to the x-axis 
    which='both',  # both major and minor ticks are affected 
    bottom='off',  # ticks along the bottom edge are off 
    top='off',   # ticks along the top edge are off 
    labelbottom='off') 
plt.legend(loc=4, prop={'size': 15}) 

pinny_mean = events_all_metrics["pinny_payback"].mean() 
ax.plot(pinny_mean, label='Pinny Mean', linestyle='--', color='red') 
plt.show() 

kambi_pinny

+1

[stripplotを使用してseabornで中央線でとの点を描画]の可能複製(https://stackoverflow.com/questions/37619952/drawing-points-with-with-median-lines-海賊使用ストライプロップ) –

答えて

0

せずに、赤と緑のデータポイントを示しています。 plotにはyとxの点が必要です。この場合、plotの代わりにplt.axhlineを使用することをお勧めします。これは、xの全範囲をカバーする定数yの線をプロットします。あなたの例:

plt.axhline(y=pinny_mean, label='Pinny Mean', linestyle='--', color='red') 
+0

おかげでティアゴ。また、画像のラベル名を変更したいと思います。ボットプロットの中にlabel = "new name"を設定しましたが、動作しません。なにか提案を? –

+0

すべてのラベル付きオブジェクトをプロットした後で 'plt.legend'を呼び出す必要があります。 – tiago

関連する問題