我对matplotlib有些新意.我要做的是编写代码,将几个数字保存到eps文件,然后生成一个复合图形.基本上我想做的就是有类似的东西
def my_plot_1():
fig = plt.figure()
...
return fig.
def my_plot_2():
fig = plt.figure()
...
return fig
def my_combo_plot(fig1,fig2):
fig = plt.figure()
gs = gridspec.GridSpec(2,2)
ax1 = plt.subplot(gs[0,0])
ax2 = plt.subplot(gs[0,1])
ax1 COPY fig1
ax2 COPY fig2
...
Run Code Online (Sandbox Code Playgroud)
之后我可以做点什么
my_combo_plot( my_plot_1() , my_plot_2() )
Run Code Online (Sandbox Code Playgroud)
并且拥有所有的数据和设置也会从由前两个函数返回的情节抄袭,但我无法弄清楚如何做到这一点与matplotlib来完成.
由于pyplot类似于状态机,我不确定你所要求的是否可行.我会反过来考虑绘图代码,如下所示:
import matplotlib.pyplot as plt
def my_plot_1(ax=None):
if ax is None:
ax = plt.gca()
ax.plot([1, 2, 3], 'b-')
def my_plot_2(ax=None):
if ax is None:
ax = plt.gca()
ax.plot([3, 2, 1], 'ro')
def my_combo_plot():
ax1 = plt.subplot(1,2,1)
ax2 = plt.subplot(1,2,2)
my_plot_1(ax1)
my_plot_2(ax2)
Run Code Online (Sandbox Code Playgroud)