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!
imshow( BW ) displays the binary image BW in a figure. For binary images, imshow displays pixels with the value 0 (zero) as black and 1 as white. imshow( X , map ) displays the indexed image X with the colormap map . imshow( filename ) displays the image stored in the graphics file specified by filename .
Occasionally, problems with Matplotlib can be solved with a clean installation of the package. In order to fully remove an installed Matplotlib: Delete the caches from your Matplotlib configuration directory. Delete any Matplotlib directories or eggs from your installation directory.
The last, Agg, is a non-interactive backend that can only write to files. It is used on Linux, if Matplotlib cannot connect to either an X display or a Wayland display.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With