11

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

7
  • 1
    Do you know Jupyter notebook: jupyter.org? Commented Jul 24, 2018 at 19:47
  • 1
    I don't know any solution. But I want to mention that I never ever used Debugging mode even when debugging. Instead, print statements are completely fine to find out the current state of a script. Commented Jul 24, 2018 at 19:47
  • Thanks for suggestions. I did use Jupyter notebook, but I'd prefer spyder. @ImportanceOfBeingErnest how do you use print statements? In command line during debug mode? When working with big (say, N=1000) vectors, visualization is more convenient Commented Jul 24, 2018 at 20:10
  • 1
    What I mean is that when not in Debugging mode, you can easily plot whatever you like at any point in the script, just as you'd do with print statements. Commented Jul 24, 2018 at 20:50
  • 1
    If you call plt.show() the script stops automatically until you close the figure. You can also trigger any error, which lets the script stop, like assert False. Commented Jul 24, 2018 at 21:13

1 Answer 1

14

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.

Sign up to request clarification or add additional context in comments.

7 Comments

I am curios about how you found this?
@Angelos by try and error
Clunky as hell, but it probably doesn't get any better! Working on Windows probably requires working with Windows-native tooling, not this good old Linux stuff that needs to be ported.
this also works with pdb in jupyter, which is extremely convenient
Wow you are an angel from up above.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.