【问题标题】:matplotlib figures are not displayed when one types imshow(img) in the command prompt in pdb mode在 pdb 模式下在命令提示符中键入 imshow(img) 时不显示 matplotlib 图形
【发布时间】:2014-07-18 14:31:07
【问题描述】:

有人在调试模式 (PDB) 下使用 spyder 遇到过这个问题吗?它在交互模式下工作正常。

一个建议的solution 是在imshow(img) 之后使用pause(1) 而不是show()

有没有更好的方法可以在调试模式下查看我的数据?如果有,那将是一个真正的 Matlab 杀手!

【问题讨论】:

    标签: python debugging matplotlib pdb spyder


    【解决方案1】:

    回答我自己的问题。显然这是bugpause(1) 是在 PDB 模式下查看绘图数据的唯一方法。

    另一种方法是通过将整个程序剪切并粘贴到命令行中来将其作为脚本运行。这样show() 可以用来代替pause(1)。这样做的好处是可以放大情节。当使用pause(1) 时,这只能在暂停期间进行。

    例如:

    import numpy as np
    from matplotlib import pyplot as plt
    import cv2
    
    file_name = 'myimage.jpg'
    img = cv2.imread(file_name)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    edges = cv2.Canny(gray,150,100,apertureSize = 3)
    
    #display image
    plt.figure(1)
    plt.imshow(edges)
    plt.title('edges of image')
    plt.show()
    

    编辑:

    我刚刚在 python 中发现了一个不错的替代绘图工具,名为 guiqwt

    与 matplotlib 不同,它适用于 pdb

    import numpy as np
    from guiqwt.pyplot import *
    figure("simple plot")
    subplot(1, 2, 1)
    plot(x, np.tanh(x+np.sin(12*x)), "g-", label="Tanh")
    legend()
    subplot(1, 2, 2)
    plot(x, np.sinh(x), "r:", label="SinH")
    show()
    

    您可以在python(x,y) 中将其作为包含的软件包的一部分获取,或者您可以从here 下载它

    编辑2:

    我刚刚发现Pycharm 发布的最新IDE 对matplotlib 的支持要好得多。您可以使用 plt.imshow(img) 甚至不必使用 plt.show() 在调试模式下显示图像

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-13
      • 2014-03-09
      • 1970-01-01
      相关资源
      最近更新 更多