2016-11-30 1 views
1

카테고리를 기준으로 박스 플롯에서 외곽 값에 다른 색상을 설정하고 싶습니다.팬더 : 하나의 박스 플롯 내에서 플라이어에 다른 색상 설정

f = plt.figure() 
ax = f.add_subplot(111) 
df = pd.DataFrame({"X":[-100,-10,0,0,0,10,100], 
        "Category":["A","A","A","A","B","B","B",]}) 
bp = df.boxplot("X", return_type="dict", ax=ax, grid=False) 
ax.set_ylim(-110,110) 
plt.text(1,90,"this flier red",ha='center',va='center') 
plt.text(1,-90,"this flier blue",ha='center',va='center') 

Different flier colors in boxplot

은 어떻게 전단지 (위 뚜껑 아래 교차) 서로 다른 색상을 줄 수 있습니까?

은 내가

bp["whiskers"][0].set_color("b") 
bp["whiskers"][1].set_color("r") 

하여 수염에 대해 서로 다른 색상을 설정할 수 있다는 사실을 알고 있으며 bp["whiskers"] 2 라인 객체 (상단 수염 하나하고 아래 하나 하나)의 목록을 반환한다는 의미가 있습니다. 그러나 bp["fliers"] 위해 나는 단지 심지어 아무것도하지 않는 한리스트 요소 (bp["fliers"].set_color("r")를 얻을.

감사를 도움.

최대

답변

2

좋아을,이 bp["fliers"].get_data(). 하나 개의 솔루션 인으로 튜플을 반환 XY 값. 그 다음 하나는

ax.plot([1],[bp["fliers"][0].get_data()[1][0]], 'b+') 
ax.plot([1],[bp["fliers"][0].get_data()[1][1]], 'r+') 

enter image description here

통해 플롯 갖는다