2.1.6.2.Matplotlib

1. 使用library

import matplotlib.pyplot as plt
  • 將matplotlib的圖表直接嵌入到Notebook之中

%matplotlib inline

2. 畫圖的基本操作

  • 使用plt.plot及numpy array

import numpy as np
x = np.linspace(0, 5, 11)
y = x ** 2
plt.plot(x, y, 'r-')
plt.xlabel('X label')
plt.ylabel('Y label')
plt.title('Title')
#print
plt.show()

3. 繪製多張圖

  • 使用plt.subplot

4.以Object Orient的概念進行繪圖操作

  • 1.使用plt.figure及add_axes

  • 2.figsize與dpi參數的使用

  • 3.legend與位置 (location code, loc)

    • loc可以設定代碼或是給tuple

  • 4.line與marker

    • color, width, style

  • 5.設定lower bound及upper bound

5.以Object Orient的概念進行多張圖的繪圖操作

  • 1.使用plt.figure及add_axes

  • 2.使用plt.subplots

  • 3.使用plt.subplots如果太擠可以用plt.tight_layout()

  • 4.figsize與dpi參數的使用

儲存圖檔

Last updated

Was this helpful?