jesseWUT
jesseWUT

Reputation: 651

Seaborn plot display out of order in ipython cell

When I run the below code, I would expect to see the Seaborn figure and then the text from the print statement underneath it, but instead it is on top.

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

tips = sns.load_dataset("tips")
sns.relplot(x = "total_bill", y = "tip", data = tips);

print('this should be at the bottom')

How can I have the print statement display underneath the Seaborn figure?

Upvotes: 1

Views: 1133

Answers (1)

Sheldore
Sheldore

Reputation: 39062

The following solution appears to work in my Jupyter Notebook when combined with plt.show() from matplotlib. Now the plot will be displayed first before the print statement gets executed.

As put simply by @ImportanceOfBeingEarnest below, in the absence of plt.show() in your cell containing the plot command, the plots will be shown at the end of the cell.

%matplotlib inline
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")
sns.relplot(x="total_bill", y="tip", data=tips)
plt.show()
print('this should be at the bottom')

Upvotes: 2

Related Questions