1. 程式人生 > >一個簡單的使用matplotlib作圖的例子

一個簡單的使用matplotlib作圖的例子

AC vol cos top one bsp stop amp ylabel

 1 #使用matplotlib作圖
 2 import numpy as np
 3 import matplotlib.pyplot as plt
 4 
 5 #x = np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
 6 x = np.linspace(0,10,1000) # 作圖的變量自變量
 7 y = np.sin(x) + 1 #因變量y
 8 z = np.cos(x**2) + 1 #因變量z
 9 
10 #plt.figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, 
11 #frameon=True, FigureClass=Figure, clear=False) 12 plt.figure(figsize=(8,4)) #設置圖像的大小為寬8,高4,單位為英寸 13 plt.plot(x,y,label = $\sin x+1$, color = red, linewidth = 2) #作圖設置標簽、線條顏色,線條大小 14 plt.plot(x,z, g--,label = $\cos x^2 + 1$) #作圖,設置標簽、線條類型 15 plt.xlabel(Time(s)) #x軸名稱 16 plt.ylabel(Volt
) #y軸名稱 17 plt.title(A Simple Example) #標題 18 plt.ylim(0,2.2) #顯示y軸範圍 19 plt.legend() #顯示圖例 20 plt.show() #顯示作圖效果

技術分享圖片

一個簡單的使用matplotlib作圖的例子