기본 콘텐츠로 건너뛰기

라벨이 최대인 게시물 표시

[matplotlib]quiver()함수

함수 그래프 그리기: 최대와 최소 찾기

작성된 그림은 전자책 파이썬과 함께하는 미분적분 에서 Chapter 5.1에서 소개한 여러 그래프들과 그 코드입니다. import numpy as np from sympy import * import matplotlib.pyplot as plt import seaborn as sns def tgline(slope, x0, y0, x): b=y0-slope*x0 re=slope*x+b return(re) def scantline(x0, y0, x1, y1, x): s, b=symbols("s, b") eq1=x0*s+b-y0 eq2=x1*s+b-y1 re=solve([eq1, eq2], (s, b)) re1=float(re[s])*x+float(re[b]) return(re1) CH 5.1 #그림 5.1.1 x=np.linspace(-4,4, 100) y=x**2 plt.figure(figsize=(4, 3)) plt.plot(x, y, color="g", label=r"f(x)=$x^2$") for i in np.arange(-3, 4): if i==-1: nme=r"$\frac{df(x)}{dx} < 0$" elif i==1: nme=r"$\frac{df(x)}{dx} \geq 0$" else: nme="" plt.plot(x, tgline(2*i, i, i**2, x), ls="--", alpha=0.5, color=['r' if i < 0 else 'b'][0], label=nme) plt.xlabel("x", loc="right", fontsize="11") plt.ylabel("y...