本文整理汇总了Python中matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg.size方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasQTAgg.size方法的具体用法?Python FigureCanvasQTAgg.size怎么用?Python FigureCanvasQTAgg.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg
的用法示例。
在下文中一共展示了FigureCanvasQTAgg.size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Window
# 需要导入模块: from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg import size [as 别名]
class Window(QWidget):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
# Set Features List
self.selectedFeatures = Clusterer.getDefaultFeatures()
self.availableFeatures = Clusterer.getAllFeatures()
self.availableFeatures &= ~self.selectedFeatures
self.initUI()
sys.stdout = EmittingStream(textWritten=self.normalOutputWritten)
self.clustererThread = ClustererThread(self)
self.clusterer = None
self.clusters = None
self.currentCluster = 0
self.backgroundColor = QtGui.QColor(0, 0, 0)
def __del(self):
sys.stdout = sys.__stdout__
def keyPressEvent(self, e):
if e.key() == QtCore.Qt.Key_Escape:
self.close()
########################################################
# Utils
def np2Qt(self, imageRGBA):
"""Convert numpy array to QPixmap.
"""
height, width, bytesPerComponent = imageRGBA.shape
bytesPerLine = bytesPerComponent * width;
qimg = QtGui.QImage(imageRGBA.data, width, height, bytesPerLine, QtGui.QImage.Format_ARGB32)
return QtGui.QPixmap.fromImage(qimg)
def checkerboard(self, size):
"""Create a checkboard.
"""
h, w = size.height(), size.width()
c0 = (191, 191, 191, 255)
c1 = (255, 255, 255, 255)
blocksize = 8
coords = np.ogrid[0:h,0:w]
idx = (coords[0] // blocksize + coords[1] // blocksize) % 2
vals = np.array([c0, c1], dtype=np.uint8)
return self.np2Qt(vals[idx])
def fitImageToScreen(self, pixmap):
"""Fit pixmap to screen.
"""
resolution = QDesktopWidget().screenGeometry()
h, w = resolution.width(), resolution.height()
w = min(pixmap.width(), w)
h = min(pixmap.height(), h)
return pixmap.scaled(QtCore.QSize(w, h), QtCore.Qt.KeepAspectRatio)
def createFeaturesList(self, features):
"""Create feature list from features flags.
"""
ql = []
for i in xrange(features):
flag = ((features >> i) & 1) << i
if flag:
ql.append(Clusterer.getFeatureName(flag))
return ql
def setPickerColor(self, color, colorPicker):
"""Set the color picker color.
"""
css = 'QWidget { background-color: %s; border-width: 1px; \
border-radius: 2px; border-color: black; border-style: outset; }'
colorPicker.setStyleSheet(css % color.name())
def refreshSource(self, img):
"""Display source image.
"""
pixmap = self.np2Qt(img)
pixmap = self.fitImageToScreen(pixmap)
checkerboard = self.checkerboard(pixmap.size())
painter = QtGui.QPainter()
painter.begin(checkerboard)
painter.drawPixmap(0, 0, pixmap)
painter.end()
self.imageLabel.setPixmap(checkerboard)
self.imageLabel.setFixedSize(pixmap.size())
def refreshCluster(self):
"""Redraw image area with current cluster.
"""
self.clusterCountLabel.setText(str(len(self.clusters)) + self.tr(' Clusters'))
self.refreshSource(self.clusters[self.currentCluster])
########################################################
# Signal handlers
#.........这里部分代码省略.........