Seaborn 플롯에 축 레이블 추가

Manav Narula 2023년1월30일
  1. set_xlabel()set_ylabel()함수를 사용하여 Seaborn 플롯에서 축 레이블 설정
  2. set()함수를 사용하여 Seaborn 플롯에서 축 레이블 설정
  3. matplotlib.pyplot.xlabel()matplotlib.pyplot.ylabel()함수를 사용하여 Seaborn 플롯의 축 레이블 설정
Seaborn 플롯에 축 레이블 추가

이 자습서에서는 Python의 seaborn 플롯에 x 및 y 축 레이블을 추가하는 방법에 대해 설명합니다.

기본적으로 plot 함수에서 x 및 y 축 값을 지정할 때 그래프는 이러한 값을 두 축의 레이블로 사용합니다. 원하는 축 레이블을 명시 적으로 추가하는 다른 방법에 대해 논의 할 것입니다.

set_xlabel()set_ylabel()함수를 사용하여 Seaborn 플롯에서 축 레이블 설정

seaborn 플롯은 matplotlib axes 인스턴스 유형 객체를 반환합니다. set_xlabel()set_ylabel을 사용하여 각각 x 및 y 축 레이블을 설정할 수 있습니다.

예를 들면

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df = pd.DataFrame(
    {"Day 1": [7, 1, 5, 6, 3, 10, 5, 8], "Day 2": [1, 2, 8, 4, 3, 9, 5, 2]}
)

p = sns.lineplot(data=df)
p.set_xlabel("X-Axis", fontsize=20)
p.set_ylabel("Y-Axis", fontsize=20)

seaborn 축 레이블 1

fontsize매개 변수를 사용하여 글꼴 크기를 제어 할 수 있습니다.

set()함수를 사용하여 Seaborn 플롯에서 축 레이블 설정

set()함수는 플롯에 다른 요소를 추가하는 데 사용되며 축 레이블을 추가하는 데 사용할 수 있습니다. xlabelylabel매개 변수를 사용하여 레이블을 지정합니다.

예를 들면

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df = pd.DataFrame(
    {"Day 1": [7, 1, 5, 6, 3, 10, 5, 8], "Day 2": [1, 2, 8, 4, 3, 9, 5, 2]}
)

p = sns.lineplot(data=df)
p.set(xlabel="X-Axis", ylabel="Y-Axis")

seaborn 축 레이블 2

matplotlib.pyplot.xlabel()matplotlib.pyplot.ylabel()함수를 사용하여 Seaborn 플롯의 축 레이블 설정

이 함수는 현재 플롯의 두 축에 대한 레이블을 설정하는 데 사용됩니다. size,fontweight,fontsize와 같은 다른 인수를 사용하여 레이블의 크기와 모양을 변경할 수 있습니다.

다음 코드는 그 사용법을 보여줍니다.

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df = pd.DataFrame(
    {"Day 1": [7, 1, 5, 6, 3, 10, 5, 8], "Day 2": [1, 2, 8, 4, 3, 9, 5, 2]}
)

p = sns.lineplot(data=df)
plt.xlabel("X-Axis")
plt.ylabel("Y-Axis")

seaborn 축 레이블 3

작가: Manav Narula
Manav Narula avatar Manav Narula avatar

Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.

LinkedIn

관련 문장 - Seaborn Label

관련 문장 - Seaborn Axis