gpt4 book ai didi

python - 在每个子图之间以适当的间距绘制子图

转载 作者:行者123 更新时间:2023-12-05 05:36:05 26 4
gpt4 key购买 nike

<分区>

我需要绘制 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()

我想知道我需要添加/进行哪些更改才能使数据值轴具有适当的间距并在不与其他子图重叠的情况下显示,而不是将那些空标签放在每个子图的底部,替换它情节外顶部的每个子情节都有一个标签

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com