1. 程式人生 > >Python3學習-Matplotlib(1)

Python3學習-Matplotlib(1)

Matplotlib安裝

  dos命令下----執行:Python -m pip install matplotlib

在這裡插入圖片描述 安裝後: 在這裡插入圖片描述測試程式碼:

import matplotlib as plt
import numpy as np 
x = np.linspace(1, 50)
y = 2*x + 1
plt.plot(x, y)
plt.show()

顯示: 在這裡插入圖片描述

figure影象

import matplotlib as plt
import numpy as np 
x = np.linspace(-1, 1, 50)
y1 = 2*x + 1
y2 = x**2

plt.figure
() plt.plot(x, y1) plt.figure() plt.plot(x, y2) plt.show()

效果: 在這裡插入圖片描述

修改figuer名:

plt.figure(num = 6)

效果: 在這裡插入圖片描述

修改figuer尺寸:

plt.figure(num = 6, figsize=(5, 4))

效果: 在這裡插入圖片描述

使figuer多資料:

plt.figure(num = 6, figsize=(5, 4))
plt.plot(x, y2)
plt.plot(x, y1)

效果: 在這裡插入圖片描述

修改線條引數: color-顏色 linewidth-寬度 linestyle-線條風格

plt.plot
(x, y1, color = 'red', linewidth = 1.0, linestyle = '--' )

在這裡插入圖片描述

效果: 在這裡插入圖片描述