Python/Basic/chick_python_exam/Unit1_basic/program/u1/test.py
2024-06-27 15:41:10 +08:00

24 lines
1.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#Program: curve_plot.py (Report bugs/comments to chikh@yuntech.edu.tw)
#Function: 繪製f(x)=x*log(1+x**2)*exp(-x**2)之函數圖形
#Note: 繪圖指令參見https://matplotlib.org/tutorials/introductory/pyplot.html
import math
import matplotlib.pyplot as plt
# from matplotlib.font_manager import FontProperties
#-------------------------------------------------------------------#
# 創建(x,f(x))對應若干位置點存於串列融合http://bit.ly/2Inq6d9介紹的寫法
N = 10000 #區間內分為10000點
xIntvLen = 6 #interval length: 區間[-3,3]寬度
x = [-3+xIntvLen*(p/N) for p in range(N+1)] #趕緊筆記起來
fx = []
for i in range(N+1): #計算每一x所對應的f(x)值儲存於fx串列
fx.append(x[i]*math.log(1+x[i]*x[i])*math.exp(-x[i]*x[i]))
#-------------------------------------------------------------------#
plt.plot(x,fx)
plt.xlabel('x'); plt.ylabel('y')
# chineseFont = FontProperties(fname = 'C:\\Windows\\Fonts\\kaiu.ttf')
# plt.xlabel(u"x軸",fontproperties = chineseFont) #參考http://bit.ly/2p46ggw
plt.show()