기본 콘텐츠로 건너뛰기

라벨이 bar인 게시물 표시

[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([...

함수의 그래프: 적분의 적용

다음 그림들은 전자책 파이썬과 함께하는 미분적분 의 7장에 수록된 그래프들과 코드들입니다. import numpy as np import pandas as pd from sympy import * import matplotlib.pyplot as plt import seaborn as sns sns.set_style("darkgrid") def axisTran(ax): ax.spines['left'].set_position(("data", 0)) ax.spines['bottom'].set_position(("data", 0)) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) #그림 7.1.1 a=symbols("a") f=(a-1)*(a-2)*(a-5)+5 x=np.linspace(0.5,5, 100) y=[f.subs(a, i) for i in x] fig,ax=plt.subplots(figsize=(4,3)) ax.plot(x, y ,color="g", label="f(x)") idx=np.linspace(0, 99, 7).astype(int) for i in range(1, len(idx)): x0=x[[(idx[i-1]),idx[i]]] y0=[f.subs(a, i) for i in x0] ax.scatter(x0, y0, s=50, c="b") ax.plot(x0, y0, ls="dashed", color="r") ax.text(x[(idx[i-1])]+0.2, f.subs(a, x[(idx[i-1])]), f"p{i-1}" , color="b"...