matplotlib-subplot多合一显示 发表于 2019-06-11 | 分类于 python 详情请看莫烦老师教程莫烦python 代码12345678910111213141516171819202122232425262728293031323334353637383940414243import matplotlib.pyplot as plt# example 1:###############################plt.figure(figsize=(6, 4))# plt.subplot(n_rows, n_cols, plot_num)plt.subplot(2, 2, 1)plt.plot([0, 1], [0, 1])plt.subplot(222)plt.plot([0, 1], [0, 2])plt.subplot(223)plt.plot([0, 1], [0, 3])plt.subplot(224)plt.plot([0, 1], [0, 4])plt.tight_layout()# example 2:###############################plt.figure(figsize=(6, 4))# plt.subplot(n_rows, n_cols, plot_num)plt.subplot(2, 1, 1)# figure splits into 2 rows, 1 col, plot to the 1st sub-figplt.plot([0, 1], [0, 1])plt.subplot(234)# figure splits into 2 rows, 3 col, plot to the 4th sub-figplt.plot([0, 1], [0, 2])plt.subplot(235)# figure splits into 2 rows, 3 col, plot to the 5th sub-figplt.plot([0, 1], [0, 3])plt.subplot(236)# figure splits into 2 rows, 3 col, plot to the 6th sub-figplt.plot([0, 1], [0, 4])plt.tight_layout()plt.show() 结果