기본 콘텐츠로 건너뛰기

라벨이 색 채우기인 게시물 표시

[matplotlib]quiver()함수

통계관련 그래프

다음 그래프들은 전자책 파이썬과 함께하는 통계이야기 4 장에 수록된 그림들의 코드들입니다. import numpy as np import pandas as pd from scipy import stats from sklearn.preprocessing import StandardScaler import FinanceDataReader as fdr import yfinance as yf import matplotlib.pyplot as plt import seaborn as sns sns.set_style("darkgrid") #fig 421 st=pd.Timestamp(2022,12, 1) et=pd.Timestamp(2023, 4, 1) da=fdr.DataReader("KS11", st, et) pop=(da['Close']-da['Open'])/da['Open']*100 np.random.seed(1) xBar=np.array([]) for i in range(20): x=pop.sample(5, random_state=i) xBar=np.append(xBar, x.mean()) xBar2=np.array([]) for i in range(100): x=pop.sample(5, random_state=i) xBar2=np.append(xBar2, x.mean()) fig, ax=plt.subplots(1, 2, figsize=(8, 3)) ax[0].hist(xBar, 10, rwidth=0.8, color="blue", label="n=20") ax[0].axvline(xBar.mean(), 0, 0.9, color="red", label=f"m={round(xBar.mean(), 2)}") ax[0].set_xlabel("x", weight=...

함수의 그래프: 정적분

다음 그림들은 전자책 파이썬과 함께하는 미분적분 의 6.3장과 6.4장에 수록된 그래프들과 코드들입니다. 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) #그림 6.3.1 a=symbols("a") f=(a-1)*(a-2)*(a-3)+3 x=np.linspace(0, 5, 100) y=[f.subs(a, i) for i in x] plt.figure(figsize=(4,3)) plt.plot(x, y ,color="g", label="f(x)") x0, x1=np.linspace(1, 2.5, 20), np.linspace(2.5, 4, 20) fy0, fy1=[float(f.subs(a, i)) for i in x0], [float(f.subs(a, i)) for i in x1] plt.fill_between(x0, fy0, color="b", alpha=0.5, label="F(x)") plt.fill_between(x1, fy1, color="r", alpha=0.5, label="F(x+h)-F(X)") plt.xticks([1, 2.5, 4], ["a=0...

함수의 그래프: 부정적분

다음 그림들은 전자책 파이썬과 함께하는 미분적분 의 6.1장에 수록된 그래프들과 코드들입니다. 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) #그림 6.1.1 x=np.linspace(0, 3, 100) y=3*x plt.figure(figsize=(4,3)) plt.plot(x, y, color="g", lw=3, label="f(x)=3x") plt.fill_between(x, y, alpha=0.6) plt.xlabel("Time(hr)", fontsize="11") plt.ylabel("Vel\n(km/hr)", rotation="horizontal", fontsize="11", labelpad=20) plt.legend(loc=(0.2, 0.9), labelcolor='g', frameon=False) plt.show() #그림 6.1.2 x=[0, 50, 125, 200] y=[400, 400, 300, 250] fig, ax=plt.subplots(figsize=(4,3)) ax.step(x, y, 'g') ax.fill_betw...