matplotlib: matplotlib.gridspec

matplotlib.gridspec:
gridspec is a module which specifies the location of the subplot in the figure.
gridspec是用来给图片分格的

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec

使用plt.figure()创建一个图像窗口, 使用gridspec.GridSpec将整个图像窗口分成3行

plt.figure()
gs = gridspec.GridSpec(3, 3)

使用plt.subplot来作图,
gs[0, :]表示这个图占第0行和所有列,
gs[1, :2]表示这个图占第1行和第2列前的所有列,
gs[1:, 2]表示这个图占第1行后的所有行和第2列,
gs[-1, 0]表示这个图占倒数第1行和第0列,
gs[-1, -2]表示这个图占倒数第1行和倒数第2列.

ax6 = plt.subplot(gs[0, :])
ax7 = plt.subplot(gs[1, :2])
ax8 = plt.subplot(gs[1:, 2])
ax9 = plt.subplot(gs[-1, 0])
ax10 = plt.subplot(gs[-1, -2])
plt.show()

这里写图片描述

参考:莫烦python

猜你喜欢

转载自blog.csdn.net/nockinonheavensdoor/article/details/80114049