2017-12-29 1 views
0

녹색의 데이터 포인트 평균과 빨간색 데이터 포인트의 평균을 갖는 두 개의 라인 (빨간색과 초록색)을 얻고 싶습니다. 다음 코드를 사용하고 있지만 작동하지 않습니다. 그것은 단지 당신의 pinny_mean는 y를 하나의 값이기 때문에이 작동하지 않는 빨간색 평균선파이썬에서 평균 라인을 겹쳐서 표시합니다.

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

가능한 중복 https://stackoverflow.com/questions/37619952/drawing-points-with-with-median-lines- : 귀하의 예를 들어 in-seaborn-using-stripplot) –

답변

0

없이, 빨간색과 녹색 데이터 포인트를 보여주는 것. plot에는 y와 x의 점이 필요합니다. 이 경우 plot 대신 plt.axhline을 사용하는 것이 좋습니다. x의 전체 범위를 포함하는 상수 y의 선을 그립니다.

plt.axhline(y=pinny_mean, label='Pinny Mean', linestyle='--', color='red') 
([시본 사용 stripplot의 중간 선으로 그리기 점]의
+0

감사합니다. 또한 이미지의 레이블 이름을 변경하고 싶습니다. 나는 bot plot 부분에 label = "new name"을 설정했지만 작동하지 않습니다. 어떠한 제안? –

+0

레이블이있는 모든 객체를 플로팅 한 후에 만'plt.legend'를 호출해야합니다. – tiago

관련 문제