Plotly 차트의 축 tick 회전 및 폰트 변경하기

Plotly x축 tick 회전 및 폰트 변경하기

Data Visualization
Plotly의 x축 tick을 변경하는 방법에 대해서 정리합니다.
Author

gabriel yang

Published

October 4, 2023

Plotly x축 tick 회전시키기

차트의 축에 표시될 tick 값의 길이가 긴 경우 tick을 회전 시키는 것이 좋습니다.

import plotly.graph_objects as go

fig = go.Figure(go.Scatter(
    mode = "lines+markers",
    y = [4, 1, 3, 1, 10, 3, 7, 11, 5, 7, 8, 2],
    x = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December",]))

fig.show()

x축과 y축의 tick의 fontsize와 회전을 적용합니다.

fig = go.Figure(go.Scatter(
    mode = "lines+markers",
    y = [4, 1, 3, 1, 10, 3, 7, 11, 5, 7, 8, 2],
    x = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December",]))

fig.update_xaxes(
        tickangle = 70,
        tickfont = {"size": 14},
        title_text = "Month",
        title_font = {"size": 20},
        title_standoff = 25)

fig.update_yaxes(
        title_text = "Temperature",
        title_standoff = 25)

tickfont로 x축의 tick의 글자크기를 설정합니다. title_font는 축 타이틀의 크기를 결정하고 title_standoff는 축과 title사이의 거리를 결정합니다.