Task01:Matplotlib初相识
阅读原文时间:2023年07月09日阅读:1
Figure:最基本的一级
Axes:在Figure上创建子图的容器(如果Figure中仅含一子图,则该容器可省略)
Axis:用于处理子图上和坐标轴和网格相关的元素
Tick:用于处理和刻度相关的元素

A.OO模式:更能实现高级绘图的需求

# step1 准备数据
x = np.linspace(0, 2, 100)
y = x**2

# step2 第五章:设置绘图样式(非必须)
mpl.rc('lines', winewidth=4, linestyle='-.')

# step3 第三章:定义布局
fig, ax = plt.subplots()

# step4 第二章:绘制图像
ax.plot(x, y, label="linear")

# step5 第四章:标签,文字和图例
ax.set_xlabel('x label')
ax.set_ylabel('y label')
ax.set_title("Simple Plot")
ax.legend()
plt.show()

B.pyplot模式:方便简洁,容易上手

# step1 准备数据
x = np.linspace(0, 2, 100)
y = x**2

# step2 第五章:设置绘图样式(非必须)
mpl.rc('lines', winewidth=4, linestyle='-.')

# step3 第二章:绘制图像
plt.plot(x, y, label="linear")

# step4 第五章:标签,文字和图例
plt.xlabel('x label')
plt.ylabel('y label')
plt.title('Simple Plot')
plt.legend()
plt.show()

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章