Python3学习-Matplotlib(1)

Matplotlib安装

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

Python3学习-Matplotlib(1)
安装后:
Python3学习-Matplotlib(1)测试代码:

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

显示:
Python3学习-Matplotlib(1)

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()

效果:
Python3学习-Matplotlib(1)

修改figuer名:

plt.figure(num = 6)

效果:
Python3学习-Matplotlib(1)

修改figuer尺寸:

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

效果:
Python3学习-Matplotlib(1)

使figuer多数据:

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

效果:
Python3学习-Matplotlib(1)

修改线条参数:
color-颜色 linewidth-宽度 linestyle-线条风格

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

Python3学习-Matplotlib(1)

效果:
Python3学习-Matplotlib(1)

相关文章:

  • 2021-09-02
  • 2021-12-14
  • 2021-06-08
  • 2021-06-24
  • 2022-01-04
猜你喜欢
  • 2021-04-23
  • 2021-04-09
  • 2021-10-30
  • 2021-09-02
  • 2021-12-26
  • 2021-11-07
  • 2022-12-23
相关资源
相似解决方案