Seaborn 플롯에서 로그 눈금을 사용하는 방법


plt.xscale()plt.yscale() 함수를 사용하여 해양 플롯에서 각각 x축과 y축에 대한 로그 눈금을 사용할 수 있습니다.

 import matplotlib. pyplot as plt
import seaborn as sns

#create scatterplot with log scale on both axes
sns. scatterplot (data=df, x=' x ', y=' y ')
plt. xscale ('log')
plt. yscale ('log')

다음 예에서는 이러한 기능을 실제로 사용하는 방법을 보여줍니다.

예: Seaborn 플롯에서 로그 척도 사용

다음과 같은 팬더 DataFrame이 있다고 가정합니다.

 import pandas as pd

#createDataFrame
df = pd. DataFrame ({' x ': [2, 5, 6, 7, 9, 13, 14, 16, 18],
                   ' y ': [200, 1700, 2300, 2500, 2800, 2900, 3400, 3900, 11000]})

#view DataFrame
print (df)

    xy
0 2 200
1 5 1700
2 6 2300
3 7 2500
4 9 2800
5 13 2900
6 14 3400
7 16 3900
8 18 11000

Seaborn의 산점도() 함수를 사용하여 x축과 y축 모두에서 선형 척도를 사용하는 산점도를 만들 수 있습니다.

 import seaborn as sns

#create scatterplot with default axis scales
sns. scatterplot (data=df, x=' x ', y=' y ')

y축에만 로그 눈금을 사용하려면 다음 구문을 사용할 수 있습니다.

 import matplotlib. pyplot as plt
import seaborn as sns

#create scatterplot with log scale on y-axis
sns. scatterplot (data=df, x=' x ', y=' y ')
plt. yscale ('log')

로그 스케일

이제 Y축은 로그 눈금을 사용합니다.

다음과 같은 경우 x축에 로그 눈금을 사용할 수도 있습니다.

 import matplotlib. pyplot as plt
import seaborn as sns

#create scatterplot with log scale on both axes
sns. scatterplot (data=df, x=' x ', y=' y ')
plt. yscale (' log ')
plt. xscale (' log ') 

이제 두 축 모두 로그 눈금을 사용합니다.

관련 항목: 언제 차트에서 로그 눈금을 사용해야 합니까?

추가 리소스

다음 튜토리얼에서는 Seaborn에서 다른 일반적인 작업을 수행하는 방법을 설명합니다.

Seaborn 플롯에 제목을 추가하는 방법
Seaborn 플롯에서 축 레이블을 회전하는 방법
Seaborn 플롯에서 축 레이블을 변경하는 방법

의견을 추가하다

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다