Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在PySide窗口中设置一个单独位置画布matplotlib_Python_Matplotlib_Pyside - Fatal编程技术网

Python 在PySide窗口中设置一个单独位置画布matplotlib

Python 在PySide窗口中设置一个单独位置画布matplotlib,python,matplotlib,pyside,Python,Matplotlib,Pyside,我在这里有这样的情况: btn_1 = QtGui.QPushButton("1", self) btn_1.move(0, 20) btn_2 = QtGui.QPushButton("3", self) btn_2.move(100, 20) btn_3 = QtGui.QPushButton("3", self) btn_3.move(200, 20) fig = pyplot.figure() #---plot things---# canvas = FigureCanvas(fi

我在这里有这样的情况:

btn_1 = QtGui.QPushButton("1", self)
btn_1.move(0, 20)

btn_2 = QtGui.QPushButton("3", self)
btn_2.move(100, 20)

btn_3 = QtGui.QPushButton("3", self)
btn_3.move(200, 20)

fig = pyplot.figure()
#---plot things---#
canvas = FigureCanvas(fig)
self.setCentralWidget(canvas) #here is the problem
我从matplotlib获得一个画布,并将其设置在PySide窗口中,但当我这样做时,小部件画布将在按钮上方生成。我想设置画布的位置

self是此类的对象:

class myForm(QtGui.QMainWindow)

您应该使用布局类,如
QHBoxLayout()
QVBoxLayout
,但我认为您的类必须继承
QWidget
(查看如何使用布局类的示例)。如果要使用
QMainWindow
(有自己的布局),必须将按钮/操作放在
QToolBar
QDockBar
QMenuBar
中。见
QMainWindow的布局

我改为QWidget并处理这些布局。我也这样写:
canvas.setParent(self)