웹사이트 검색

Seaborn Distplot: 종합 가이드


여러분! 이 기사에서는 Seaborn Distplot에 대해 자세히 설명합니다.

Seaborn Distplot이란 무엇입니까?

Distplot 또는 distribution plot은 데이터 분포의 변화를 나타냅니다. Seaborn Distplot은 연속 데이터 변수의 전체 분포를 나타냅니다.

Matplotlib 모듈과 함께 Seaborn 모듈은 다양한 변형이 있는 distplot을 묘사하는 데 사용됩니다. Distplot은 데이터를 히스토그램과 선으로 표시합니다.

Seaborn Distplot 만들기

Python Seaborn 모듈에는 데이터를 플로팅하고 데이터 변형을 묘사하는 다양한 기능이 포함되어 있습니다. seaborn.distplot() 함수는 distplot을 그리는 데 사용됩니다. distplot은 데이터의 일변량 분포, 즉 밀도 분포에 대한 변수의 데이터 분포를 나타냅니다.

통사론:

seaborn.distplot()

seaborn.distplot() 함수는 데이터 변수를 인수로 받아들이고 밀도 분포가 포함된 플롯을 반환합니다.

예 1:

import numpy as np
import seaborn as sn
import matplotlib.pyplot as plt

data = np.random.randn(200)
res = sn.distplot(data)
plt.show()

numpy.random.randn() 함수를 사용하여 무작위 데이터 값을 생성했습니다. 또한 pyplot.show() 함수를 사용하여 플롯을 표시합니다.

산출:

예 2:

import numpy as np
import seaborn as sn
import matplotlib.pyplot as plt
import pandas as pd

data_set = pd.read_csv("C:/mtcars.csv")
data = pd.DataFrame(data_set['mpg'])
res = sn.distplot(data)
plt.show()

pandas.read_csv() 함수는 데이터세트를 Python 환경으로 로드합니다.

산출:

DistPlot의 축에 레이블 추가

Seaborn Distplot은 아래 구문을 사용하여 데이터 값을 Pandas Series로 변환하여 축의 레이블과 함께 제공될 수 있습니다.

통사론:

pandas.Series(data,name='name')
seaborn.distplot()

Pandas Series에는 데이터 축의 레이블을 설정하는 'name' 매개변수가 포함되어 있습니다.

예:

import numpy as np
import seaborn as sn
import matplotlib.pyplot as plt

data = np.random.randn(200)
res = pd.Series(data,name="Range")
plot = sn.distplot(res)
plt.show()

산출:

커널 밀도 추정 플롯과 함께 Seaborn DistPlot

Seaborn Distplot은 Kernel Density Estimate Plot과 함께 클럽화되어 다양한 데이터 값에 걸쳐 연속 변수의 분포 확률을 추정할 수 있습니다.

통사론:

seaborn.distplot(data,kde=True)

kde 매개변수는 True로 설정되어 distplot과 함께 커널 밀도 플롯을 활성화합니다.

예:

import numpy as np
import seaborn as sn
import matplotlib.pyplot as plt

data = np.random.randn(100)
res = pd.Series(data,name="Range")
plot = sn.distplot(res,kde=True)
plt.show()

산출:

Rug Plot과 함께 Seaborn DistPlot으로 데이터 시각화

Rug Plot과 함께 Seaborn Distplot을 매핑하여 일변량 데이터 변수와 관련하여 빈에 대한 데이터 분포를 나타낼 수 있습니다. Rug Plot은 빈 형태의 데이터 분포를 시각화하여 설명합니다.

통사론:

seaborn.distplot(data, rug=True, hist=False)

러그 플롯 배포를 활성화하려면 'rug' 매개변수를 True로 설정해야 합니다.

예:

import numpy as np
import seaborn as sn
import matplotlib.pyplot as plt

data = np.random.randn(100)
res = pd.Series(data,name="Range")
plot = sn.distplot(res,rug=True,hist=False)
plt.show()

산출:

세로축을 따라 Seaborn Distplot 플로팅

아래 구문을 사용하여 전체 Distplot을 y축에 그릴 수 있습니다.

통사론:

seaborn.distplot(data,vertical=True)

y축에 distplot을 그리려면 'vertical' 매개변수를 True로 설정해야 합니다.

예:

import numpy as np
import seaborn as sn
import matplotlib.pyplot as plt

data = np.random.randn(100)

plot = sn.distplot(data,vertical=True)

plt.show()

산출:

seaborn.set() 함수를 사용하여 다른 스타일 설정

Seaborn에는 플롯에 추가 배경 기능을 추가하는 여러 가지 내장 기능이 있습니다. seaborn.set() 함수는 분포도에 다른 배경을 설정하는 데 사용됩니다.

통사론:

seaborn.set(style)

예:

import numpy as np
import seaborn as sn
import matplotlib.pyplot as plt
sn.set(style='dark',)
data = np.random.randn(500)

plot = sn.distplot(data)

plt.show()

산출:

사용자 정의 색상을 Seaborn DistPlot으로 설정

seaborn.distplot() 함수의 'color' 매개변수를 사용하여 데이터의 시각화에 추가하기 위해 distplot에 다른 색상을 설정할 수 있습니다.

통사론:

seaborn.distplot(data, color='color')

예:

import numpy as np
import seaborn as sn
import matplotlib.pyplot as plt

sn.set(style='dark',)
data = np.random.randn(500)
plot = sn.distplot(data,color='purple')

plt.show()

산출:

결론

따라서 Matplotlib 모듈과 함께 Seaborn 모듈은 데이터 시각화를 돕고 데이터 분포를 묘사합니다.

데이터 시각화의 기본 사항을 이해하기 위해 모든 독자가 Python Matplotlib 모듈을 읽을 것을 강력히 권장합니다.

참조

  • Seaborn distplot() 함수 – 문서