기본 콘텐츠로 건너뛰기

라벨이 step인 게시물 표시

[matplotlib]quiver()함수

확률, 통계 관련 그래프

다음 그래프들은 전자책 파이썬과 함께하는 통계이야기 3 장에 수록된 그림들의 코드들입니다. import numpy as np import pandas as pd from scipy import stats import matplotlib.pyplot as plt import seaborn as sns sns.set_style("darkgrid") #fig 311 uni, p=[0, 1, 2],[0.25, 0.5, 0.25] fig, ax=plt.subplots(figsize=(4,3)) ax.bar(uni, p, color="g", alpha=0.3) ax.set_xlabel("# of head(H)") ax.set_ylabel("PMF") ax.set_yticks(p) ax.set_xticks(uni) plt.show() #fig 312 import itertools ca=list(itertools.product(range(1, 7), repeat=2)) S=[sum(i) for i in ca] uni, fre=np.unique(S, return_counts=True) fresum=sum(fre) p=[i/fresum for i in fre] fig, ax=plt.subplots(figsize=(4,3)) ax.bar(uni, p, color="g", alpha=0.3) ax.set_xlabel("Sum of number") ax.set_ylabel("PMF") ax.set_yticks(np.array(p).round(3)) ax.set_xticks(uni) plt.show() #fig 313 ca=list(itertools.product([0, 1], repeat=2)) S=[sum(i) for i in ca] uni, fre=np.unique(S, return_counts=True) re=pd.DataFrame([...

[seaborn] 데이터분포의 시각화 1(histplot & displot)

데이터분포의 시각화(histplot & displot) 데이터 분포의 이해는 다양한 통계 분석의 기반이 됩니다. seaborn의 figure-level 함수인 displot(), jointplot(), pairplot()와 axes-level 함수인 hisplot(), kedplot(), ecdplot(), rugplot()으로 분포를 시각화 할 수 있습니다 Figure-level과 Axes-level 함수 그리고 히스토그램 참조). 분포의 시각화에 가장 일반적인 접근은 히스토그램(histogram)입니다. 히스토그램은 일정한 구간(bin)으로 그룹화한 변수를 기준으로 각 구간의 빈도수 또는 밀도를 대응시킨 bar plot입니다. 이 기사에서는 각 빈도에 빈도수(Count)를 나타내기 위해 histplot() 과 displot() 으로 작성에 대해 소개합니다. import numpy as np from sklearn.datasets import make_blobs import pandas as pd from sklearn.preprocessing import StandardScaler import matplotlib.pyplot as plt plt.rcParams['font.family'] ='NanumGothic' plt.rcParams['axes.unicode_minus'] =False import seaborn as sns import yfinance as yf 히스토그램을 작성하기 위한 데이터로 코스피 지수의 일일자료(^KS11)를 모듈 yfiance를 사용하여 호출합니다. 그 자료에서 에 대해 일일변화율(시가에 대한 종가의 변화율)과 일간 거래량(Volume)의 변화율을 목록화하여 첨가하여 다음코드의 결과인 kos1df 자료를 생성합니다. st=pd.Timestamp(2023, 10, 17) et=pd.Timestamp(2024, 10, 17) kos=yf.download("^K...