如何在我的 GUI 上绘图
我正在使用 PyQt 设计一个 GUI,当我单击一个按钮来绘制我创建的函数的数据图时,我需要显示一个 matplotlib/pylab 窗口。它就像 Matlab 中使用的运行时。每次按下该按钮时,我都想将 matplotlib/pylab 窗口保留为我的窗口。
I'm designing a GUI with PyQt
where I need to display a matplotlib/pylab window when I click on a button that makes the plot of the data from a function I've created. It's like a runtime used in Matlab. I want to keep the matplotlib/pylab window as my window everytime I press that button.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果我理解正确的话,您有一个带有 GUI 的应用程序,并且您想在 GUI 使用的单独窗口中绘制图形。 pyqtgraph 可以很好地做到这一点。
首先在命令提示符中输入
pip install pyqtgraph
来安装 pyqtgraph,然后
在此处查看更多信息:
http://www.pyqtgraph.org/documentation/how_to_use.html
If I understand you correctly you have an application with a GUI and you want to plot a graph in a separate window than the GUI uses.
pyqtgraph
can do this nicely.first type
pip install pyqtgraph
in the command prompt to install pyqtgraphthen
more info here:
http://www.pyqtgraph.org/documentation/how_to_use.html
下面是一个基本示例,它将使用 QThread 绘制三个不同的样本:
Here is a basic example that will plot three different samples using a
QThread
:这是来自 user1006989 (最佳答案)的代码,适用于 PyQt5,希望对某人有用:
这是一个基本示例,它将使用 QThread 绘制三个不同的示例:
This is code from user1006989 (best answer) adapted to PyQt5, hopefully it will be useful to someone:
Here is a basic example that will plot three different samples using a QThread:
Eli Bendersky 编写了一个在 PyQt 中使用 matplotlib 的代码示例: http ://eli.thegreenplace.net/2009/01/20/matplotlib-with-pyqt-guis/
Eli Bendersky has written a code example that uses matplotlib within PyQt: http://eli.thegreenplace.net/2009/01/20/matplotlib-with-pyqt-guis/
将 Matplotlib 与 PyQt 集成需要一些工作。这是一个例子:
http://sourceforge.net/mailarchive/message.php?msg_id=29086544
然而,有一些专门围绕 PyQt 设计的绘图库:
Integrating Matplotlib with PyQt takes a little work. Here's an example:
http://sourceforge.net/mailarchive/message.php?msg_id=29086544
However, there are a few plotting libraries designed specifically around PyQt: