简体   繁体   English

在 Python 中调试期间绘制函数

[英]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.我曾经在 Matlab 中工作,使用plot函数在调试期间可视化中间结果非常方便(在使用大数组/矩阵和嵌套函数时)。

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).在 Python 中,我无法在调试模式下绘制任何内容:永远不会加载带有图形图的窗口(我使用 Spyder IDE 进行编码,使用matplotlib.pyplot进行绘图)。

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谢谢,米哈伊尔

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.您需要做的就是发出plt.pause(1)命令,该命令将显示绘图,然后可以继续调试过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM