如何在 python 程序的简单 UI 中显示实时图表?
我有一个复杂的算法来更新存储在数组中的 3 个直方图。我想调试我的算法,所以我正在考虑在用户界面中将数组显示为直方图。做到这一点最简单的方法是什么。 (快速的应用程序开发比优化的代码更重要。)
我有一些使用 Qt(C++)的经验和一些 matplotlib 的经验。
(我将把这个问题留一两天,因为如果没有我没有的更多经验,我很难评估解决方案。希望社区的投票将有助于选择最佳答案。)
I have a complicated algorithm that updates 3 histograms that are stored in arrays. I want to debug my algorithm, so I was thinking of showing the arrays as histograms in a user interface. What is the easiest way to do this. (Rapid application development is more important than optimized code.)
I have some experience with Qt (in C++) and some experience with matplotlib.
(I'm going to leave this question open for a day or two because it's hard for me to evaluate the solutions without a lot more experience that I don't have. Hopefully, the community's votes will help choose the best answer.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我建议在交互模式下使用 matplotlib,如果你调用
.show
一次,那么它会在自己的窗口中弹出,如果你不这样做,那么它只存在于内存中,并且可以在以下情况下写入文件你已经完成了。I recommend using matplotlib in interactive mode, if you call
.show
once then it will pop up in its own window, if you don't then it exists only in memory and can be written to a file when you're done with it.哦,现在看,当你说实时时,你的意思是你想要高于 5 Hz 的刷新率,matplotlib 无法完成这项工作。我以前遇到过这个问题,我选择了与 PyQt 一起使用的 PyQwt 。
Ouh, now see, when you say real time you mean you want a refresh rate higher than 5 Hz matplotlib won't do the job. I had this problem before, I went for PyQwt that works with PyQt.
编辑:如今,使用
matplotlib.animation
更容易、更好:有一个制作动画图的示例此处。
在此示例的基础上,您可以尝试以下操作:
通过这种方式,我可以获得每秒大约 14 帧,而使用代码我可以得到每秒 4 帧 首次发布。诀窍是避免要求 matplotlib 绘制完整的图形。而是调用
plt.hist
一次,然后操作patches
中现有的matplotlib.patches.Rectangle
来更新直方图,并调用fig.canvas.draw()
使更新可见。Edit: Nowadays, it is easier and better to use
matplotlib.animation
:There is an example of making an animated graph here.
Building on this example, you might try something like:
I can get about 14 frames per second this way, compared to 4 frames per second using the code I first posted. The trick is to avoid asking matplotlib to draw complete figures. Instead call
plt.hist
once, then manipulate the existingmatplotlib.patches.Rectangle
s inpatches
to update the histogram, and callfig.canvas.draw()
to make the updates visible.对于实时绘图,我建议尝试 Chaco、pyqtgraph 或任何基于 opengl 的库,如 glumpy 或 visvis。 Matplotlib 尽管很精彩,但通常不适合此类应用。
编辑: glumpy、visvis、galry 和 pyqtgraph 的开发人员都在合作开发一个名为 vispy 的可视化库。它仍处于开发早期,但前景光明并且已经相当强大。
For realtime plotting, I recommend trying Chaco, pyqtgraph, or any of the opengl-based libraries like glumpy or visvis. Matplotlib, wonderful as it is, is generally not suitable for this kind of application.
Edit: the developers of glumpy, visvis, galry, and pyqtgraph are all collaborating on a visualization library called vispy. It is still early in development, but promising and already quite powerful.