Matplotlib入門

教程在此,點擊教程中的圖片會有相應的代碼。
總結如下:
在matplotlib.artist裏面有兩種類型:primitives和containers,primitives包含基本的圖形元素,如線Line2D,Rectangle, Text, AxesImage,Containers是容器,基本圖形元素都是畫在上面的,container包括Figure,axes,axis等。

簡單圖

  1. 默認設置 plt.figure ; plt.plot()
  2. 設置座標範圍 plt.xlim(); plt.ylim()
  3. 設置刻度值 plt.xticks(); plt.yticks(),和刻度值的展示標籤
  4. 移動座標軸,不固定在左下角。ax.spines[‘right’].set_color(‘none’)
  5. 添加標註 先plt.plot(),最後plt.legend()
  6. 對某些點添加註釋plt.scatter畫點,plt.annotate()註釋
  7. 刻度值被遮擋,可以調節透明度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()

發佈了34 篇原創文章 · 獲贊 7 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章