5

I have two matplotlib (seaborn) figure objects both made in different ipython cells.

#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

How can I "show" them one after another in the same cell. I have matplotlib inline turned on.

#third cell
fig_1
fig_2
>>Only shows fig_2
Thomas K
  • 39,200
  • 7
  • 84
  • 86
jwillis0720
  • 4,329
  • 8
  • 41
  • 74

4 Answers4

6

You can use plt.show() after each image:

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()
2

You just need to import the display function from the IPython.display module:

from IPython.display import display
import seaborn

%matplotlib inline

g1 = seaborn.factorplot(**options1)
g2 = seaborn.factorplot(**options2)

display(g1)
display(g2)
Paul H
  • 65,268
  • 20
  • 159
  • 136
0

What about this?

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)
richar8086
  • 177
  • 4
  • 13
0
//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 !!!
Aditya Aggarwal
  • 159
  • 1
  • 9