【发布时间】:2015-10-07 14:25:42
【问题描述】:
我希望打印语句的输出与绘图交错,按照它们在 Ipython 笔记本单元格中打印和绘制的顺序。例如,考虑以下代码:
(使用 ipython notebook --no-browser --no-mathjax 启动 ipython)
%matplotlib inline
import matplotlib.pyplot as plt
i = 0
for data in manydata:
fig, ax = plt.subplots()
print "data number i =", i
ax.hist(data)
i = i + 1
理想的输出应该是这样的:
data number i = 0
(histogram plot)
data number i = 1
(histogram plot)
...
但是,Ipython 中的实际输出将如下所示:
data number i = 0
data number i = 1
...
(histogram plot)
(histogram plot)
...
在 Ipython 中是否有直接的解决方案,或者解决方法或替代解决方案来获得隔行输出?
【问题讨论】:
-
如果你使用
%matplotlib inline,我想你可以调用fig.show()当你想要显示的情节。 -
已编辑以包含
%matplotlib inline。另外在ax.hist(data)之后调用fig.show()并没有改变结果。 -
plt.show()呢? -
plt.show()成功了
标签: python matplotlib ipython ipython-notebook