【问题标题】:Function with matplotlib object in subplot子图中带有 matplotlib 对象的函数
【发布时间】:2020-05-16 08:24:48
【问题描述】:

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

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)

如何将地块置于子地块中的正确位置?

【问题讨论】:

    标签: function matplotlib subplot


    【解决方案1】:

    绘图时指定坐标轴:

    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])
    

    【讨论】:

      猜你喜欢
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      • 2015-04-27
      • 2017-05-22
      • 2021-03-02
      • 2012-03-13
      • 1970-01-01
      • 2018-04-13
      相关资源
      最近更新 更多