Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python Pandas의 열로 계층화된 Boxplot

<시간/>

Python 클래스에서 열로 계층화된 상자 그림을 만들기 위해 다음 단계를 수행할 수 있습니다. -

단계

  • Figure 크기를 설정하고 서브플롯 사이와 주변의 패딩을 조정합니다.

  • 2차원, 크기 변경 가능, 잠재적으로 이질적인 표 형식 데이터의 Pandas 데이터 프레임을 만듭니다.

  • 데이터 세트의 히스토그램을 계산합니다.

  • 열로 시작하는 상자 그림을 만듭니다.

  • 그림을 표시하려면 show()를 사용하세요. 방법.

import pandas as pd
import numpy as np
from matplotlib import pyplot as plt

# Set the figure size
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

# Pandas dataframe
df = pd.DataFrame({"column1": [4, 6, 7, 1, 8], "column2": [1, 5, 7, 8, 1]})

# Compute the histogram
_, breaks = np.histogram(df.column1, bins=5)

# Create the boxplot
ax = df.boxplot(column='column1', by='column2')

# Display the plot
plt.show()

출력

다음 출력을 생성합니다 -

Python Pandas의 열로 계층화된 Boxplot