Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode - Display an image while debugging

I am currently using visual studio code to debug a python file. In that python file is a numpy image. When i try to import matplotlib to display the image, it doesn't show:

- plt.imshow(pred_scores)
<matplotlib.image.AxesImage object at 0x7f3d43e691d0>
- plt.show()
None
- pred_scores
array([[0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
...

Basically nothing happens. Is it actually possible to show an image here?

like image 770
raaj Avatar asked Apr 18 '26 09:04

raaj


2 Answers

There's an extension allows you to view images/plots during python debugging. You simply select the image variable in the editor, and click on the light bulb will appear near it. Basically, it just save the image into a temporary location, and open it on the side.

Disclaimer: I'm the author of the extension.

https://marketplace.visualstudio.com/items?itemName=elazarcoh.simply-view-image-for-python-debugging

like image 88
Elazarcoh Avatar answered Apr 21 '26 00:04

Elazarcoh


You could use VS Code Jupyter Interactive Windows to render your plots.

At the entry script of your solution code base (e.g. main.py), either start a debugging session in Interactive Window (> Jupyter: Debug Current File in Interactive Window) from the command palette, or, as I prefer, add #%% at the first line and click Debug Cell.

enter image description here

You can now interactively render your plots during a VS Code debugging session, regardless of whether it is locally or remotely

enter image description here

There is a discussion about this on GitHub

https://github.com/microsoft/vscode-jupyter/issues/1278

like image 39
fabda01 Avatar answered Apr 20 '26 23:04

fabda01



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!