简体   繁体   English

在QtDesigner中绘制matplotlib小部件

[英]Drawing in a matplotlib widget in QtDesigner

I created in QtDesigner this QDialog: 我在QtDesigner中创建了这个QDialog:

在此处输入图片说明

I would like to know how can I draw something in this Matplotlib widget that I put there. 我想知道如何在放置在那里的Matplotlib小部件中绘制一些东西。 I mean, if I write some code to create a matplotlib figure without Qt Designer, I can write something like: 我的意思是,如果我编写一些代码以在没有Qt Designer的情况下创建matplotlib图,那么我可以编写如下内容:

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)

and then draw doing: 然后画做:

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

How can I access to this widget to draw something? 如何访问此小部件以绘制东西? Hope you can help me. 希望您能够帮助我。

Based on the screenshot that you have provided, it seems that the MatplotlibWidget should be accessible as self.matplotlibwidget from within your QMainWindow class. 根据您提供的屏幕截图,看起来MatplotlibWidget应该可以从QMainWindow类中作为self.matplotlibwidget访问。 This is because of the value listed in the "Object" column of the Object Inspector. 这是由于在对象检查器的“对象”列中列出的值。

You can use this object directly to add plots to your GUI. 您可以直接使用此对象将图添加到GUI。

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

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

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