기본 콘텐츠로 건너뛰기

라벨이 arrow인 게시물 표시

[matplotlib]quiver()함수

벡터와 행렬에 관련된 그림들

다음의 코드들과 그림들은 전자책 파이썬과 함께 하는 선형대수 에 수록된 것입니다. import numpy as np import matplotlib.pyplot as plt import seaborn sns.set_style("darkgrid") #fig 1.1.1 fig, ax=plt.subplots(figsize=(3,2)) cord=[(0,0), (3,1),(2,3)] nme=["O","A","B"] col=['g','b','r'] for i, j in enumerate(cord): ax.scatter(j[0], j[1], color="white", edgecolors=col[i]) ax.text(j[0], j[1]+0.15, nme[i], color=col[i], fontweight="bold") ax.arrow(0,0, 3, 1, color="b", head_width=0.1) ax.arrow(0,0, 2, 3, color="r", head_width=0.1) ax.text(1, 0.5, r"$\vec{a}$", color="b") ax.text(1, 1.8, r"$\vec{b}$",color="r") 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) ax.grid(True) plt.show() #fig112 a=np.array([10,15])...

기술 통계 관련 그래프

다음 그래프들은 전자책 파이썬과 함께하는 통계이야기 0, 1, 2 장에 수록된 그림들의 코드들입니다. 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 021 plt.figure(figsize=(4,3)) plt.subplot(1,2,1) plt.arrow(0,0, 1, 2, width=0.02, color="b", label="vecor a") plt.legend(loc="best", labelcolor="linecolor", frameon=False) plt.title("(a)") plt.subplot(1,2,2) plt.arrow(0,0, 1, 2, width=0.02, color="g", label="vector a1") plt.arrow(0,0, 2, 1, width=0.02, color="r", label="vector a2") plt.yticks([]) plt.legend(loc="best", labelcolor="linecolor", frameon=False) plt.title("(b)") plt.show() #fig 031 x=np.sort(stats.norm.rvs(loc=2, scale=np.sqrt(3), size=1000, random_state=3)) y=stats.norm.pdf(x, loc=2, scale=np.sqrt(3)) plt.figure(figsize=(5,3)) plt.hist(x, bins=10, density=True, alpha=0.2, rwidth=0.8) plt....

함수의 그래프: 최소제곱법

다음 그림들은 전자책 파이썬과 함께하는 미분적분 의 8장에 수록된 그래프들과 코드들입니다. import numpy as np import pandas as pd from sympy import * import matplotlib.pyplot as plt import seaborn as sns sns.set_style("darkgrid") #그림 8.4.1 x=np.array([1.,2.,3.,4.]) y0=np.array([5.2, 8.9, 11.7, 16.8]) y=3.76*x+1.25 y1=3.96*x+1 y2=3.36*x+1.2 plt.figure(figsize=(8, 3)) plt.subplot(121) col=['g', 'b', 'r'] for i,j in enumerate([y, y1, y2]): if i>0: l="--" else: l="-" plt.plot(x, j, color=col[i], ls=l, label=f"fit{i+1}") plt.scatter(x, y0, s=50, c="brown", label="observed") plt.xlabel("x", fontsize=11) plt.ylabel("f(x)", rotation="horizontal",labelpad=10, fontsize=11) plt.legend(loc=(0.1, 0.6), labelcolor="linecolor", frameon=False) plt.subplot(122) plt.plot(x, y, color="g", label="reg. line") plt.scatter(x, y, s=50, c="b", label="predicted...