Matplotlib可视化(十)--面向对象绘图 VS matlabstyle

三种方式简介:
1.pyplot:经典高层封装,到目前为止,我们所用的都是pyplot
2.pylab:将matlab和numpy合并的模块,模拟matlab的编程环境
3.面对对象的方式:matplotlib的精髓,更基础和底层的方式

  • pylab

无需多个前缀,但是不建议使用

from pylab import *
x = arange(10)
y = randn(len(x))
plot(x, y)
title('pylab')
show()

  • 面向对象
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(10)
# y = np.random.randn(len(x))
y = np.sin(x)
fig = plt.figure()#生成一张画布对象
ax = fig.add_subplot(111)#生成坐标轴对象
l,=plt.plot(x, y)
t = ax.set_title('object oriented')
plt.show()

三种方式的图片其实都是一样的

一般建议用面向对象+pyplot

猜你喜欢

转载自blog.csdn.net/qq_42007339/article/details/104642672