#題目: y=a*sin(b*x+c)+d 與 y=sin x 函數圖形的關係
#Python 程式碼如下
import numpy as np
import matplotlib.pyplot as plt
a=1.0
b=2.0
c=-0.0
d=0.0
# 產生x座標的資料,從 -2PI 到 2PI
x1 = np.arange(-2*np.pi, 2*np.pi,0.1)
x2 = np.arange(-2*np.pi, 2*np.pi,0.02)
Sin_y1 = np.sin(x1)
Sin_y2 = a*np.sin(b*x2+c)+d
plt.figure(figsize=(8,6),dpi=80)
ax = plt.gca() # gca stands for 'get current axis'
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))
plt.plot(x1,Sin_y1, color="red", linewidth=2.0, linestyle=":", label="y=sin(x)")
plt.plot(x2,Sin_y2, color="blue", linewidth=2.0, linestyle="-", label="y=a*sin(b*x+c)+d")
plt.legend(loc='upper right')
plt.show()
# 輸出結果如下:
# y=a*sin(b*x+c)+d 與 y=sin x 函數圖形的關係
訂閱:
文章 (Atom)