绘制多个子图
subplot() 方法:在绘图时需要指定位置
subplots() 方法:可以一次生成多个,在调用时只需要调用生成对象的 ax 即可。
subplots() 方法
文档:https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html
matplotlib.pyplot.subplots(nrows=1, ncols=1, *, sharex=False, sharey=False, squeeze=True, subplot_kw=None, gridspec_kw=None, **fig_kw)
参数说明:
sharex, shareybool or {‘none’, ‘all’, ‘row’, ‘col’}控制x (sharex)或y (sharey)轴之间的属性共享
默认:False
- True或’all’: x或y轴将在所有子图中共享。
- False或’none’:每个子图x轴或y轴将是独立的。
- ‘row’:每个子图行将共享一个x轴或y轴。
- col’:每个子plot列将共享一个x轴或y轴。
tight_layout:自动调整子图参数,使之填充整个图像区域。它仅仅检查坐标轴标签、刻度标签以及标题的部分。
fig, ax = plt.subplots()
fig, axes = plt.subplots(23)
# 即表示一次性在figure上创建成2*3的网格,使用plt.subplot()只能一个一个的添加
plt.gray()函数
用于将颜色映射设置为“gray”