matplotlib 是否可以从现有地物对象创建子地块?

flseospp  于 2023-10-24  发布在  其他
关注(0)|答案(1)|浏览(104)

我有一个列表,上面有一系列已经存在的图形,它们的x轴相同,我想把它们堆叠在一个画布上。例如,我在这里分别生成两个图形--我如何把它们放在一个图上?

import matplotlib.pyplot as plt

time = [0, 1, 2, 3, 4]
y1 = range(10, 15)
y2 = range(15, 20)

## Plot figure 1
fig1 = plt.figure()
plt.plot(time, y1)

## plot figure 2
fig2 = plt.figure()
plt.plot(time, y2)

## collect in a list
figs = [fig1, fig2]

plt.subplot(1, 1, 1)
## code to put fig1 here

plt.subplot(1, 1, 2)
## code to put fig2 here
c8ib6hqw

c8ib6hqw1#

有:

import matplotlib.pyplot as plt
from matplotlib import gridspec

time = [0, 1, 2, 3, 4]
y1 = range(10, 15)
y2 = range(15, 20)

plt.figure(figsize = (5,10))
fig = gridspec.GridSpec(2, 1, height_ratios=[1,1])

x1 = plt.subplot(fig[0])
plt.plot(time, y1)

x2 = plt.subplot(fig[1])
plt.plot(time, y2)

输出:

相关问题