ipython 单元格中的 Seaborn 图显示顺序不正确

Seaborn plot display out of order in ipython cell

当我 运行 下面的代码时,我希望看到 Seaborn 图,然后是它下面打印语句中的文本,但它却在顶部。

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

如何让打印语句显示在 Seaborn 图形下方?

当与 matplotlib 中的 plt.show() 结合使用时,以下解决方案似乎适用于我的 Jupyter Notebook。现在将在执行 print 语句之前首先显示绘图。

正如下面 @ImportanceOfBeingEarnest 所简单说明的那样,如果您的单元格中没有包含绘图命令的 plt.show(),绘图将显示在单元格的末尾。

%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')