【问题标题】:make matplotlib imshow blocking print() in a for loop在 for 循环中使 matplotlib imshow 阻塞 print()
【发布时间】:2016-05-20 03:29:42
【问题描述】:

在 ipython 笔记本中,我在这样的 for 循环中使用 matplotlib.pyplot imshow:

for i in range(3):
    plt.figure()
    plt.imshow(I[i])
    print("some explanation for image " + str(i))

基本上我希望显示每张图片后跟一个打印输出的句子。但是我得到的是3个句子一起打印出来,然后是3个图像。

我尝试在 print() 之前使用 time.sleep(1) 但不起作用。任何想法让 plt.imshow() 和 print() 的输出相互交错?

【问题讨论】:

标签: python matplotlib


【解决方案1】:

不是你要求的,但它会达到同样的目的:

for i in range(3):
    plt.figure()
    plt.imshow(I[i])
    plt.title("some explanation for image " + str(i))

【讨论】:

  • 谢谢。我使用了与您的代码类似的东西:使用 ax.annotation() 将文本注释添加到一边。
猜你喜欢
  • 1970-01-01
  • 2014-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-16
  • 1970-01-01
  • 1970-01-01
  • 2017-11-08
相关资源
最近更新 更多