【发布时间】:2016-02-09 16:32:31
【问题描述】:
我在 Spyder IDE 中编写了一些 Python 来并排绘制一对图像,以便我可以直观地检查它们。大部分时间我只需要 3 秒来查看它们,但每隔一段时间我需要更长的时间来仔细查看。因此,我没有使用 time.sleep,而是将其编码为等待我按下 Enter 键,如下所示:
import matplotlib.pyplot as plt
import os
def VI_segmentation():
root = os.getcwd()
NR_dir = root + '\\Neurite_Results\\'
SO_dir = root + '\\Segmentation_Overlays\\'
jpgs = os.listdir(NR_dir)
fig = plt.figure(figsize=(20,12))
for jpg in jpgs:
fig.suptitle(jpg , fontsize=14, fontweight='bold')
image_NR = plt.imread(NR_dir + jpg)
image_SO = plt.imread(SO_dir + jpg)
plt.subplot(121)
plt.imshow(image_NR)
plt.subplot(122)
plt.imshow(image_SO)
plt.draw()
plt.pause(0.01)
input('Press Enter to continue')
VI_segmentation()
问题是我的思维速度比我的电脑快:)。计算机需要 5 或 6 秒才能响应 Enter 键,并在响应后再过几秒钟进行更新。在浏览数百张大部分都很好的图像时,会导致糟糕的人体工程学。任何简化此代码的想法将不胜感激。
【问题讨论】:
-
因为除了你之外没有人拥有这些图片,你需要提供更多信息。至少在您的机器上运行缓慢的原因,请阅读有关分析的内容:stackoverflow.com/questions/5478351/…
标签: python matplotlib spyder