gpt4 book ai didi

python - jupyter笔记本中的plt.subplot

转载 作者:太空宇宙 更新时间:2023-11-03 13:56:29 26 4
gpt4 key购买 nike

def plot_it(U1, U2, x, i):
fig_1, = plt.plot(x, U1)
fig_2, = plt.plot(x, U2)
i = str(int(i/2 + 1)) if i != 0 else ''
plt.xlabel('x, t =' + i + 'Δt')
plt.ylabel('U')
plt.legend(handles=[fig_1, fig_2], labels=['μ = 1', 'μ = 2'])
plt.show()

plt.figure()
for i in range(11):
U1[1:20] = np.linalg.solve(A1, B1.dot(U1[1:20]))
U2[1:20] = np.linalg.solve(A2, B2.dot(U2[1:20]))
if i % 2 == 0:
plt.subplot(2, 3, int(i/2 + 1))
plot_it(U1, U2, x, i)

我想要的结果是2行3列,但实际上它给了我6行1列, enter image description here

最佳答案

我没有你的 x、A1、A2 等,所以我只是展示如何使用子图 -

from matplotlib import pyplot as plt

x = [1,2,3,4,5,6,7]

fig, axes = plt.subplots(2, 3)

def plot_it(U1, U2, x, i, ax):
ax.plot(x, U1)
ax.plot(x, U2)
i = str(int(i/2 + 1)) if i != 0 else ''
fig_1 = ax.set_xlabel('x, t =' + i + 'dt')
fig_2 = ax.set_ylabel('U')
ax.legend(handles=[fig_1, fig_2], labels=['Test'])

plt.figure()
for i in range(11):
U1 = [2,4,6,9,2,1, 2]
U2 = [7, 9, 12, 78, 2, 12, 12]
if i % 2 == 0:
plot_it(U1, U2, x, i, axes[(i%4)/2, i/4])

关于python - jupyter笔记本中的plt.subplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49568625/

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