본문 바로가기
DataScience/Python

파이썬 차트 라이브러리 추천 plotly (커스터 마이징이 좋다)

by leopard4 2022. 12. 23.

파이썬 차트를 그리는 라이브러리는 matplotlib , seaborn 가 보편적이지만

인터랙티브하게 만들거나 커스터마이징을 하려면 꽤나 머리가 아프다

그래서  plotly 를 사용하면 보다 나은 차트를 구현 할 수 있다.

 

https://plotly.com/python/

 

다음 코드는 아래 차트를 그리는 예시이다.

fig = make_subplots(rows=2, cols=2,subplot_titles=last_df.columns[1:])

fig.add_trace(
    go.Scatter(x=last_df['index'], y=last_df['Score'],name="Score",
        
        mode="markers+text",
        text=last_df['index'].values,
#         text=["Text A", "Text B", "Text C"],
        textposition="bottom center"
              
              ),
    row=1, col=1
)

fig.add_trace(
    go.Scatter(x=last_df['index'], y=last_df['Trend'],name='Trend',
              mode="markers+text",
        text=last_df['index'].values,
        textposition="bottom center"
              ),
    row=1, col=2
)

fig.add_trace(
    go.Scatter(x=last_df['index'], y=last_df['Win %'],name='Win %',
              mode="markers+text",
        text=last_df['index'].values,
        textposition="bottom center"),
    row=2, col=1
)
fig.add_trace(
    go.Scatter(x=last_df['index'], y=last_df['KDA'],name='KDA',
              mode="markers+text",
        text=last_df['index'].values,
        textposition="bottom center"),
    row=2, col=2
)

fig.update_layout(height=600, width=800,legend_title="Legend", title_text="선택한 영웅과 같은 포지션의 평균 스탯을 비교합니다")


fig.update_xaxes(title_text="xaxis 1 title", row=1, col=1)
fig.update_xaxes(title_text="xaxis 2 title", range=[-1,2], row=1, col=2)
fig.update_xaxes(title_text="xaxis 3 title", showgrid=False, row=2, col=1)
fig.update_xaxes(title_text="xaxis 4 title", row=2, col=2) # 파라미터 type="log"

fig.update_yaxes(title_text="yaxis 1 title", row=1, col=1)
fig.update_yaxes(title_text="yaxis 2 title", range=[0, 10], row=1, col=2)
fig.update_yaxes(title_text="yaxis 3 title", showgrid=False, row=2, col=1)
fig.update_yaxes(title_text="yaxis 4 title", row=2, col=2)

fig.show()