教程在此,點擊教程中的圖片會有相應的代碼。
總結如下:
在matplotlib.artist裏面有兩種類型:primitives和containers,primitives包含基本的圖形元素,如線Line2D,Rectangle, Text, AxesImage,Containers是容器,基本圖形元素都是畫在上面的,container包括Figure,axes,axis等。
簡單圖
- 默認設置 plt.figure ; plt.plot()
- 設置座標範圍 plt.xlim(); plt.ylim()
- 設置刻度值 plt.xticks(); plt.yticks(),和刻度值的展示標籤
- 移動座標軸,不固定在左下角。ax.spines[‘right’].set_color(‘none’)
- 添加標註 先plt.plot(),最後plt.legend()
- 對某些點添加註釋plt.scatter畫點,plt.annotate()註釋
- 刻度值被遮擋,可以調節透明度alpha
Figures, Subplots, Axes and Ticks
Figures對象
Subplot對象和Axes對象
Subplot和Axes類似,不過Axes可以任意設置範圍,可以重疊。plt.axes([left, bottom, width, height])
Ticks對象
matplotlib.ticker.Locator 可以設置刻度的格式 ax.xaxis.set_major_locator(locator)
更多用法
Artist文檔
動畫模擬
matplotlib.animation.FuncAnimation()