在QtDesigner中绘制matplotlib小部件

在QtDesigner中绘制matplotlib小部件

本文介绍了在QtDesigner中绘制matplotlib小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在QtDesigner中创建了这个QDialog:

I created in QtDesigner this QDialog:

我想知道如何在放置在其中的Matplotlib小部件中绘制东西.我的意思是,如果我编写一些代码以在没有Qt Designer的情况下创建matplotlib图形,那么我可以编写以下内容:

I would like to know how can I draw something in this Matplotlib widget that I put there. I mean, if I write some code to create a matplotlib figure without Qt Designer, I can write something like:

self.figure_canvas = FigureCanvas(Figure())

self.axes = self.figure_canvas.figure.add_subplot(111)

x = np.arange(0,5,0.5)
y = np.sin(x)

然后画图:

ax.plot(x,y)self.axes.plot(x,y)

如何访问此小部件以绘制某些东西?希望你能帮助我.

How can I access to this widget to draw something? Hope you can help me.

推荐答案

基于您提供的屏幕快照,看来MatplotlibWidget应该可以从QMainWindow类中以self.matplotlibwidget的形式访问.这是由于对象检查器的对象"列中列出的值.

Based on the screenshot that you have provided, it seems that the MatplotlibWidget should be accessible as self.matplotlibwidget from within your QMainWindow class. This is because of the value listed in the "Object" column of the Object Inspector.

您可以直接使用该对象 将图添加到GUI中.

You can use this object directly to add plots to your GUI.

self.matplotlibwidget.axes.plot(x, y)

这篇关于在QtDesigner中绘制matplotlib小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 18:18