Function 子批次中带有matplotlib对象的函数

Function 子批次中带有matplotlib对象的函数,function,matplotlib,subplot,Function,Matplotlib,Subplot,我正在用python创建饼图,由于自定义,我在函数中编写饼图。 现在,我想创建一个子图,其中每个图都是函数的输出。但是,生成的piechart有空格,如何去掉多余的空格? 请参考下面的代码,我是否遗漏了什么 a= pd.DataFrame([1,2,3]) def test(x): x.plot.pie(y=0); fig= plt.figure(); # create a figure object fig.add_subplot(1, 2, 1); # create a

我正在用python创建饼图,由于自定义,我在函数中编写饼图。 现在,我想创建一个子图,其中每个图都是函数的输出。但是,生成的piechart有空格,如何去掉多余的空格? 请参考下面的代码,我是否遗漏了什么

a= pd.DataFrame([1,2,3])

def test(x):
    x.plot.pie(y=0);



fig= plt.figure();  # create a figure object

fig.add_subplot(1, 2, 1);  # create an axes object in the figure
test(a)


fig.add_subplot(1, 2, 2) ; # create an axes object in the figure
test(a)
如何在子地块中将地块置于正确位置


打印时指定轴:

fig, ax = plt.subplots(1, 2)  

def test(x, ax):
    x.plot.pie(y=0, ax=ax)

test(a, ax[0])
test(a, ax[1])