<分区>
我需要绘制 6 个数据子图,目前我在间距方面遇到了问题。我的图需要在每个子图的顶部有一个带有样本索引的标题。我的问题是由于间距不当,绘图可视化很困难。下面是一个可重现的例子:
import matplotlib.pyplot as pp
import matplotlib.pyplot as plt
from numpy import random
x1 = random.randint(2000, size=(125))
x2 = random.randint(1000, size=(125))
plt.subplot(2, 3, 1)
pp.plot(x1, label="Class 1", color='red')
pp.plot(x2, label="Class 2", color='blue')
leg = pp.legend(loc='lower center', bbox_to_anchor=[0.5, 1.1], ncol=2)
pp.title("Sample 7")
x1 = random.randint(2000, size=(125))
x2 = random.randint(1000, size=(125))
plt.subplot(2, 3, 2)
pp.plot(x1, color='red')
pp.plot(x2, color='blue')
leg = pp.legend(loc='lower center', bbox_to_anchor=[0.5, 1.1], ncol=2)
pp.title("Sample 2")
x1 = random.randint(2000, size=(125))
x2 = random.randint(1000, size=(125))
plt.subplot(2, 3, 3)
pp.plot(x1, color='red')
pp.plot(x2, color='blue')
leg = pp.legend(loc='lower center', bbox_to_anchor=[0.5, 1.1], ncol=2)
pp.title("Sample 3")
x1 = random.randint(2000, size=(125))
x2 = random.randint(1000, size=(125))
plt.subplot(2, 3, 4)
pp.plot(x1, color='red')
pp.plot(x2, color='blue')
pp.title("Sample 9")
leg = pp.legend(loc='lower center', bbox_to_anchor=[0.5, 1.1], ncol=2)
x1 = random.randint(2000, size=(125))
x2 = random.randint(1000, size=(125))
plt.subplot(2, 3, 5)
pp.plot(x1, color="red")
pp.plot(x2, color="blue")
pp.title("Sample 11")
leg = pp.legend(loc='lower center', bbox_to_anchor=[0.5, 1.1], ncol=2)
x1 = random.randint(2000, size=(125))
x2 = random.randint(1000, size=(125))
plt.subplot(2, 3, 6)
pp.plot(x1, color="red")
pp.plot(x2, color="blue")
pp.title("Sample 13")
leg = pp.legend(loc='lower center', bbox_to_anchor=[0.5, 1.1], ncol=2)
plt.show()
我想知道我需要添加/进行哪些更改才能使数据值轴具有适当的间距并在不与其他子图重叠的情况下显示,而不是将那些空标签放在每个子图的底部,替换它情节外顶部的每个子情节都有一个标签