Python 中的绘图matplotlib mayavi库
python matplotlib 圖像可視化
python-data-visualization-course
Interactive Web Plotting for Python
Interactive Web Plotting for Python-github
待整理的
Matplotlib
Introduction to Matplotlib and basic line
matplotlib——一個 2D 繪圖庫,可產生出版物質量的圖表 http://matplotlib.org/
matplotlib庫則能夠快速地繪制精美的圖表、以多種格式輸出,并且帶有簡單的3D繪圖的功能。
matplotlib官方網址: http://matplotlib.sourceforge.net
Introduction to Matplotlib and basic line
figures and axes
import matplotlib.pyplot as plt fig = plt.figure(figsize=(5, 2), facecolor='black') ax = fig.add_subplot(3, 2, 2) fig, axes = plt.subplots(5, 2, figsize=(5, 5)) ax = fig.add_axes([left, bottom, width, height])
figures and axes properities
fig.suptitle('title') # big figure title fig.subplots_adjust(bottom = 0.1, right=0.8, top=0.9, wspace=0.2, hspce=0.5) fig.tight_layout(pad=0.1, h_pad=0.5, w_pad=0.5, rect=None) ax.set_xlabel('xbla') ax.set_ylabel('ybla') ax.set_xlim(1, 2) #sets x limits ax.set_ylim(3,4) #set y limimits ax.set_title('blabla') ax.set(xlable='bla') ax.legend(loc='upper center') ax.grid(True, which='both') bbox = ax.get_position() bbox.xo + bbox.width
plotting routines
ax.plot(x,y, '-o', c='red', lw=2, lable='bla') ax.scatter(x,y, s=20, c=color) ax.pcolormesh(xx, yy, zz, shading ='gouraud') ax.colormesh(xx, yy, zz, norm=norm) ax.contour(xx, yy, zz, cmap='jet') ax.contourf(xx, yy, zz, vmin=2, vmax=4) n, bins, patch = ax,hist(x, 50) ax.imshow(matrix, origin ='lower', extent(x1, x2, y1, y2)) ax.specgram(y, FS=0.1, noverlap=128, scale ='linear')
2D繪圖
#序之前的代碼 def functionI(fi,ks,n,a,e0):return e0*ks*((-350*np.sin(fi)+(700*np.sqrt(3)/2)*np.cos(fi))**n)*a*a*np.cos(fi) from matplotlib import pyplot as plt plt.figure(1) #圖1:n不變,ks變化 #fi的取值范圍 0-pi/2,分100個點 fi = np.linspace(0,np.pi/2,100) ax1 = plt.subplot(211) plt.sca(ax1) #ks = 0.1-0.9 n=5 for ks in range(1,10):ks = ks*0.1plt.plot(fi,functionI(fi,ks,3,1,e0),label='ks='+str(ks))plt.legend(loc='upper right',bbox_to_anchor = (1, 1.15)) plt.xlabel(u'角度fi') plt.ylabel(u'n=5,ks變化 輻射強度I') ax2 = plt.subplot(212)#ks = 0.5,n=2-10 for n in range(2,11):plt.plot(fi,functionI(fi,0.5,n,1,e0),label='n='+str(n))plt.legend(loc='upper right',bbox_to_anchor = (1, 1.15)) plt.xlabel(u'角度fi') plt.ylabel(u'ks=0.5,n變化 輻射強度I') plt.show()
np.linspace:構造線性list,用來取點,其實畫函數圖像的本質就是畫很多點,然后連接起來。
plt.figure:運行以后,一個figure對應一個plt.show(),其實就是對應一個窗口。
plt.subplot:一個figure里有多少個圖像(坐標軸),每次運行這個返回一個ax坐標軸對象,每次走完這行代碼,就選中這個ax,接下來的操作都是在這個ax上完成的。
plt.legend:圖例顯示。
以上函數的所有的參數都可以在matplotlib參考文檔中找到。
3D建模
import numpy as np from mayavi import mlab x, y = np.mgrid[-3:3:150j,-3:3:150j] z =x**2+y**2+2 surf = mlab.surf(x, y, z, colormap='RdYlBu', warp_scale='auto') surf.actor.property.interpolation = 'phong' #對應參數表面反射率和n高光系數 surf.actor.property.specular = 0.5 #ks surf.actor.property.specular_power = 2 #n mlab.show()
References
Python科學計算和繪圖入門
機器學習入門必備的13張小抄
總結
以上是生活随笔為你收集整理的Python 中的绘图matplotlib mayavi库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 多种在线地图综合对比,Google,必应
- 下一篇: python -pass的用法