Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot a function during debugging in Python

I used to work in Matlab and it is really convenient (when working with big arrays/matrices and nested functions) to visualize intermediate results during debugging using plot function.

In Python I cannot plot anything in debug mode: a window with figure plot is never loaded (I am using Spyder IDE for coding and matplotlib.pyplot for plotting).

This is really annoying when debugging nested function and classes. Does anyone know a good solution? Of course, I can always output intermediate results, however it is not convenient.

Thanks, Mikhail

like image 489
Mikhail Genkin Avatar asked Mar 31 '26 01:03

Mikhail Genkin


1 Answers

Ok, I found a way to show the plot without breaking the debugging process.

All you need to do is to issue plt.pause(1) command, which will display the plots, and then one can continue the debugging process.

like image 145
Mikhail Genkin Avatar answered Apr 02 '26 14:04

Mikhail Genkin



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!