그리고 아래는 누적분포함수로 표현하는 방법.
import matplotlib.pyplot as plt
import numpy as np
# 임의의 데이터 생성
data = np.random.normal(0, 1, 1000)
# 누적 분포 데이터 계산
hist, bin_edges = np.histogram(data, bins=30, density=True)
cumulative = np.cumsum(hist) * np.diff(bin_edges)
# 누적 분포 그래프 생성
plt.plot(bin_edges[1:], cumulative, 'b-')
# 제목 및 레이블 추가
plt.title('Cumulative Distribution Plot')
plt.xlabel('Value')
plt.ylabel('Cumulative Probability')
# 그래프 표시
plt.show()
`np.histogram` 함수로 누적 분포 데이터를 계산한 후, `plt.plot` 함수를 사용하여 그래프 그리기.
이 코드는 데이터에 대한 누적 분포를 계산하고, 이를 선 그래프로 표시합니다. `np.cumsum` 함수는 히스토그램의 누적 합을 계산하며, `np.diff(bin_edges)`는 막대 간의 간격을 곱하여 밀도를 정규화합니다. 결과적으로, 이 그래프는 데이터가 각 값 이하일 확률을 나타냅니다.