简体   繁体   中英

Drawing in a matplotlib widget in QtDesigner

I created in QtDesigner this QDialog:

在此处输入图片说明

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)

and then draw doing:

ax.plot(x,y) or 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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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