Ploty (기능 살펴보기)

김혜민·2024년 4월 3일

Python

목록 보기
5/11

1. Hover Label

  • 데이터 시각화에서 마우스를 해당 데이터 포인트 위로 올렸을 때 나타나는 정보
# Hover Label의 스타일 설정
fig.update_layout(
        hoverlabel_bgcolor="white",
        hoverlabel_font_size=10,
        hoverlabel_font_color='black',
        hoverlabel_font_family="Rockwell")

fig.show()

# Hover Label의 세부내용 설정
fig.update_traces(hovertemplate='총 매출: %{text}달러 <br>'<br>은 엔터라고 보면 됨!
                                '날짜: %{x} <br>'+
                                 '판매량 : %{y}개')

fig.show()

2. Slider

  • 슬라이더를 조작하여 특정 범위의 값을 선택하거나 조정
fig.update_layout(xaxis=dict(rangeslider_visible=True)) # x축 기준 슬라이더

3. Drop Down

  • 여러 옵션 중 하나 선택
import plotly.graph_objects as go

fig = go.Figure()

# 1번 그래프
fig.add_trace(go.Line(
    name="옵션 1 이름",
    x=data["col"],
    y=data["col"]
    ))

# 2번 그래프
fig.add_trace(go.Line(
    name="옵션 2 이름",
    x=data["col"],
    y=data["col"]
    ))

fig.update_layout(
    updatemenus=[
        dict(
            type="dropdown",
            direction="down",
            buttons=list([
                dict(label="Both",
                     method="update",
                     args=[{"visible": [True, True]},
                           {"title": "선택시 보여질 그래프 제목"}]),
                dict(label="BottlesSold",
                     method="update",
                     args=[{"visible": [True, False]},← 첫번째 그래프 보여주기(True), 두번째 그래프 안보여주기(False)
                           {"title": "선택시 보여질 그래프 제목",}]),
                dict(label="SaleDollars",
                     method="update",
                     args=[{"visible": [False, True]},← 첫번째 그래프 안보여주기(False), 두번째 그래프 보여주기(True)
                           {"title": "선택시 보여질 그래프 제목",}]),
            ]),
        ),
    ]
)

fig.show()
profile
성장하는 주니어 데이터 분석가입니다!

0개의 댓글