【python】畫線----Matplotlib 模塊學習系列(一)

使用到的方法

  1. plt.figure() //可以理解爲聲明窗口
  2. plt.plot() // 線的座標值
  3. plt.show() // 顯示
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-1,1,50) //取值範圍以及點數
y = 2*x+1 //方程
plt.figure(num=4, figsize=(4,3)) // 窗口名稱 和 大小
plt.plot(x,y, color='red', linewidth=4) // 畫線
plt.show()

在這裏插入圖片描述

多條線

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-1,1,50)
y1 = x**2
y2 = 2*x+1
plt.figure(num=4, figsize=(4,3))
plt.plot(x,y1, color='red', linewidth=2)
plt.plot(x,y2, color='green', linewidth=2, linestyle='--')
plt.show()

在這裏插入圖片描述

多窗口

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-1,1,50)
y1 = x**2
y2 = 2*x+1

plt.figure(num=4, figsize=(4,3))
plt.plot(x,y1, color='red', linewidth=2)

plt.figure(num=1, figsize=(4,3))
plt.plot(x,y2, color='red')

plt.show()

在這裏插入圖片描述

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