차밍이

[Python] Plotly legend(범례) 의 모든 것 - 순서, 위치, 폰트 등 본문

파이썬/데이터 시각화

[Python] Plotly legend(범례) 의 모든 것 - 순서, 위치, 폰트 등

2022. 7. 23. 10:46
반응형

목차

    Legend 이름 및 순서 설정

    legendrank 를 통해서 순서의 우선순위를 줄 수 있다.

    name 에 설정해준 값이 legend로 표시된다.

    fig = go.Figure()
    fig.add_trace(go.Bar(name="fourth", x=["a", "b"], y=[2,1], legendrank=4))
    fig.add_trace(go.Bar(name="second", x=["a", "b"], y=[2,1], legendrank=2))
    fig.add_trace(go.Bar(name="first", x=["a", "b"], y=[1,2], legendrank=1))
    fig.add_trace(go.Bar(name="third", x=["a", "b"], y=[1,2], legendrank=3))
    
    fig.show()

     

    Legend 위치

    fig.update_layout(
    	legend=dict(
            orientation="h", # 가로 방향으로
            yanchor="top", y=0.99, # y축 방향 위치 설정
            xanchor="left", x=0.01, # x축 방향 위치 설정
    	)
    )

     

    Legend 폰트 및 글자 크기 등 스타일링

    fig.update_layout(
        legend=dict(
            x=0, y=1,
            traceorder="reversed",
            title_font_family="Times New Roman",
            font=dict(
                family="Courier",
                size=12,
                color="black"
            ),
            bgcolor="LightSteelBlue",
            bordercolor="Black",
            borderwidth=2
        )
    )

     

    [Python] Plotly 자주 사용하는 Layout 설정 - title, 축 label, font, subtitle, position 등

     

    [Python] Plotly 자주 사용하는 Layout 설정 - title, 축 label, font, subtitle, position 등

    Plotly 그래프를 그릴 때 마다 레이아웃 설정하는 부분들이 생각이 안나서 찾아보는 경우가 많다. 그래서 자주 사용하는 layout 설정 소스코드를 작성해서 필요한 부분에 맞게 복분할 수 있도록 앞

    chancoding.tistory.com

    [Python] Plotly 축 반전, x축 y축 반전 뒤집기

     

    [Python] Plotly 축 반전, x축 y축 반전 뒤집기

    Y축 반전 뒤집기 기본 수식 작성 import plotly.graph_objects as go import numpy as np x = np.arange(-5, 6) y = x**3 fig = go.Figure(data=go.Scatter(x=x, y=y)) fig.show() 축 반전 fig.update_layout( ya..

    chancoding.tistory.com

    [Python] Plotly 그래프 사용법 - Line Plot

     

    [Python] Plotly 그래프 사용법 - Line Plot

    Plotly를 사용해서 Line plot을 그려보겠습니다. 1. Plotly Express - Lineplot express 객체를 통해서 lineplot을 그릴 수 있습니다. plotly에 있는 기본 데이터를 가져와서 그려보겠습니다. import plotly.expr..

    chancoding.tistory.com

    Plotly를 사용한 파이썬 시각화 using 코로나 데이터셋

     

    Plotly를 사용한 파이썬 시각화 using 코로나 데이터셋

    안녕하세요. 오늘은 plotly를 사용해서 데이터 시각화 및 EDA를 진행했던 내용을 포스팅하려고 합니다. plotly는 쉽게 사용할 수 있으면서도 matplotlib보다 더 예쁘고 인터랙티브 한 자료를 만들 수 있

    chancoding.tistory.com

    .

    반응형

    관련된 글 보기

    Comments