matplotlib figures are not displayed when one types imshow(img) in the command prompt in pdb mode
debugging, matplotlib, pdb, python, spyder
Solution
To answer my own question. Apparently this is bug and the `pause(1)` is the only way to see plot figures in PDB mode.
The other method is to run the entire program as a script by cutting and pasting it into the command line. This way `show()` can be used instead of `pause(1)`. The advantage to doing it this way, is one can zoom in on the plot. When using `pause(1)` this is only possible during the pause.
For example:
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()
Edit:
I just discovered a nice alternative plotting tool in python called guiqwt.
It works with pdb unlike matplotlib
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()
You can get it as part of the included packages in python(x,y) or you can download it from here
Edit2:
I just found out the latest IDE released by Pycharm supports matplotlib much better. You can use plt.imshow(img) and don't even have to use plt.show() to display the image in debug mode
Problem
Has anyone encountered this problem using spyder in debug mode (PDB)? It works fine in the interactive mode. One suggested solution was to use `pause(1)` instead of `show()` after `imshow(img)`. Is there a better way to see my figures in debug mode? If there was, it would be a real Matlab killer!