我正在使用pyQT并希望在我创建的GUI上绘制图像。
我用:
# a figure instance to plot on
self.figure = plt.figure()
self.figure.suptitle('My Test Figure')
self.figure.set_facecolor('k')
# this is the Canvas Widget that displays the `figure`
# it takes the `figure` instance as a parameter to __init__
self.canvas = FigureCanvas(self.figure)
#I use GridLayout
layout = QtGui.QGridLayout()
#Make equal size columns
layout.setColumnStretch(0,1)
layout.setColumnStretch(1,1)
layout.setColumnStretch(2,1)
layout.setColumnStretch(3,1)
layout.setColumnStretch(4,1)
layout.setColumnStretch(5,1)
layout.setColumnStretch(6,1)
#Add a toolbar and the canvas widget
layout.addWidget(self.toolbar,0,0,1,2) #spans 1 row, 3 columns
layout.addWidget(self.canvas,1,0,4,4)
..在函数中我使用
将图像绘制到画布上 ax2=plt.subplot(1,1,1)
''' Load Image from File '''
M=plt.imread('c:\Image01.tif')
ax2.hold(False)
plt.imshow(M,cmap='gray')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
但是图像没有填充画布(黑色),它只是部分填充即使我使用子图(1,1,1)。
任何人都可以帮助我填充我在gridlayout中声明的画布区域。 enter image description here