我创建了两个函数来制作两个特定的图形,并返回相应的图像:
import matplotlib.pyplot as plt
x = range(1,100)
y = range(1,100)
def my_plot_1(x,y):
fig = plt.plot(x,y)
return fig
def my_plot_2(x,y):
fig = plt.plot(x,y)
return fig
现在,在我的函数之外,我想创建一个带有两个子图的图形,并将我的函数图形添加到其中。就像这样:
my_fig_1 = my_plot_1(x,y)
my_fig_2 = my_plot_2(x,y)
fig, fig_axes = plt.subplots(ncols=2, nrows=1)
fig_axes[0,0] = my_fig_1
fig_axes[0,1] = my_fig_2
然而,只是将创建的图形分配给这个新图形并不起作用。函数调用了图形,但它没有分配到子图中。有没有一种方法能够将我的函数图形放置在另一个图形的子图中?
def my_plot_1(x, y, ax):
,ax.plot(x, y)
。 - BigBen