파이썬 차트를 그리는 라이브러리는 matplotlib , seaborn 가 보편적이지만
인터랙티브하게 만들거나 커스터마이징을 하려면 꽤나 머리가 아프다
그래서 plotly 를 사용하면 보다 나은 차트를 구현 할 수 있다.
다음 코드는 아래 차트를 그리는 예시이다.
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()
'DataScience > Python' 카테고리의 다른 글
파이썬 원본 폴더에 이미지 파일 여러개를 일정비율로 나눠서, 랜덤으로 파일의 순서를 바꾼다음, 새로운폴더를 생성하여 넣는 방법 (0) | 2022.12.30 |
---|---|
이미지 url을 가져올때 없는 이미지인지 체크하는 방법 (0) | 2022.12.23 |
두 개의 데이터 프레임을 서브 플롯으로 배치해보자 (0) | 2022.12.22 |
Streamlit 이미지 크기를 조절하기 (0) | 2022.12.22 |
Pandas 행과 열의 문자열인덱스를 숫자로 가져오는 방법 (0) | 2022.12.16 |