【发布时间】:2018-08-15 18:37:23
【问题描述】:
我想在 matplotlib 中创建一个子图,比如 2 行和 2 列,但我只有 3 件事要绘制,并且希望保持 左下角 子图为空。但是,我仍然希望在那个位置有一个 y 轴标签,它应该是指整个第二行。
这是我目前的代码:
import matplotlib.pyplot as plt
x = [0, 1]
y = [2, 3]
ax = plt.subplot2grid((2, 2), (0, 0))
ax.plot(x, y)
ax.set_ylabel('first row')
ax = plt.subplot2grid((2, 2), (0, 1))
ax.plot(x, y)
ax = plt.subplot2grid((2, 2), (1, 0))
ax.set_ylabel('second row')
# ax.axis('off') <---- This would remove the label, too
ax = plt.subplot2grid((2, 2), (1, 1))
ax.plot(x, y)
plt.show()
我尝试过使用axis('off'),但这也删除了标签。 (同样,如果我将它向上移动一行,即在 ax.set_ylabel('second row') 上方。
所以到目前为止的结果是这样的:
我希望空的白色框(不仅仅是它的黑色边界框或刻度和刻度标签)消失。这可能吗?如果可以,我该如何实现?
【问题讨论】:
标签: python matplotlib