【问题标题】:render two seaborn figure objects in same ipython cell在同一个 ipython 单元格中渲染两个 seaborn 图形对象
【发布时间】:2016-12-24 15:10:59
【问题描述】:

我有两个 matplotlib (seaborn) 图形对象,它们都是在不同的 ipython 单元格中制作的。

#One Cell
fig_1_object = sns.factorplot(y='freq',x='d_fam',col='easy_donor',kind="bar",data=collection_d_fam)
fig_1 = fig_1_object.fig


#Two Cell
fig_2_object = sns.factorplot(y='freq',x='d_fam',col='easy_donor',kind="bar",data=collection_c_fam)
fig_2 = fig_2_object.fig

我怎样才能在同一个单元格中一个接一个地“显示”它们。我打开了 matplotlib 内联。

#third cell
fig_1
fig_2
>>Only shows fig_2

【问题讨论】:

    标签: python matplotlib ipython jupyter-notebook seaborn


    【解决方案1】:

    您只需要从IPython.display 模块中导入display 函数:

    from IPython.display import display
    import seaborn
    
    %matplotlib inline
    
    g1 = seaborn.factorplot(**options1)
    g2 = seaborn.factorplot(**options2)
    
    display(g1)
    display(g2)
    

    【讨论】:

      【解决方案2】:

      这个怎么样?

      plt.figure(1, figsize=(5,10))
      plt.subplot(211)
      # Figure 1
      sns.factorplot(y='freq',x='d_fam',col='easy_donor',kind="bar",data=collection_d_fam)
      plt.subplot(212)
      # Figure 2
      sns.factorplot(y='freq',x='d_fam',col='easy_donor',kind="bar",data=collection_c_fam)
      

      【讨论】:

        【解决方案3】:

        您可以在每张图片之后使用 plt.show():

        sns.factorplot(y='freq',x='d_fam',col='easy_donor',kind="bar",data=collection_d_fam)
        plt.show()
        
        sns.factorplot(y='freq',x='d_fam',col='easy_donor',kind="bar",data=collection_c_fam)
        plt.show()

        【讨论】:

          【解决方案4】:
          //For displaying 2 or more fig in the same row or columns :-
          
          fig, axs = plt.subplots(ncols=2,nrows=2,figsize=(14,5))
          
          //The above (ncols) take no of columns and (nrows) take no of rows and (figsize) to enlarge the image size.
          
          sns.countplot(x=data['Rating'],palette="rocket",ax=axs[0][0])
          sns.countplot(x=data['Rating'][0:50],palette="rocket",ax=axs[1][0])
          sns.countplot(x=data['Rating'],palette="rocket",ax=axs[0][0])
          sns.countplot(x=data['Rating'][0:50],palette="rocket",ax=axs[1][0])`
          //Here in any plot u want to plot add **ax** and pass the position and you are ready !!!
          

          【讨论】:

            猜你喜欢
            • 2020-04-23
            • 1970-01-01
            • 2019-05-14
            • 2013-04-29
            • 2021-07-03
            • 2021-02-16
            • 1970-01-01
            • 2013-10-28
            • 1970-01-01
            相关资源
            最近更新 更多