sách gpt4 ai đã đi

python - jupyter笔记本中的plt.subplot

In lại 作者:太空宇宙 更新时间:2023-11-03 13:56:29 26 4
mua khóa gpt4 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.hiển thị()

plt. hình()
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列, nhập mô tả hình ảnh ở đây

1 Câu trả lời

我没有你的 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. hình()
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
太空宇宙
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com