matplotlib 學習筆記 精簡 python畫圖工具

本文只做簡單概述,總結來自:菜鳥教程 https://www.runoob.com/w3cnote/matplotlib-tutorial.html

簡單的繪圖,瞭解流程,看代碼,結果如圖:

import numpy as np
import matplotlib.pyplot as plt

X = np.linspace(-np.pi, np.pi, 256, endpoint=True)
C,S = np.cos(X), np.sin(X)

plt.plot(X,C)
plt.plot(X,S)

plt.show()

from pylab import *
scatter(X,Y) #畫散點
bar(x,height)#畫柱子,x座標,柱子高度
text(x,y,string)#寫字,座標x,y, string寫的字
ylim(bottom,top)#限制y軸顯示 xlim同理
imshow(img)#畫圖像
pie([0.1,0.2,0.5]) #餅狀圖

3D圖 

from pylab import *
from mpl_toolkits.mplot3d import Axes3D

fig = figure()
ax = Axes3D(fig)
X = np.arange(-4, 4, 0.25)
Y = np.arange(-4, 4, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)

ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='hot')

show()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章