当前位置: 首页>>代码示例>>Python>>正文


Python FigureCanvasQTAgg.buffer_rgba方法代码示例

本文整理汇总了Python中matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.buffer_rgba方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasQTAgg.buffer_rgba方法的具体用法?Python FigureCanvasQTAgg.buffer_rgba怎么用?Python FigureCanvasQTAgg.buffer_rgba使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg的用法示例。


在下文中一共展示了FigureCanvasQTAgg.buffer_rgba方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import buffer_rgba [as 别名]
    def __init__(self, parent=None): #========================================
        super(ImageViewer, self).__init__(parent)
        
        self.scaleFactor = 0
        self.scaleStep = 1.2
        self.pan = False
        
        #---- image container Set Up ----
        
        self.imageLabel = QtGui.QLabel()
        self.imageLabel.setBackgroundRole(QtGui.QPalette.Base)
        self.imageLabel.setSizePolicy(QtGui.QSizePolicy.Ignored,
                                      QtGui.QSizePolicy.Ignored)
        self.imageLabel.setScaledContents(True)
        self.imageLabel.installEventFilter(self)
        
        self.imageLabel.setFrameStyle(QtGui.QFrame.Panel | QtGui.QFrame.Raised)
        self.imageLabel.setLineWidth(2)
        self.imageLabel.setMidLineWidth(1)        
        
        #---- Scroll Area Set Up ----
        
        self.scrollArea = QtGui.QScrollArea(self)
        self.scrollArea.setWidget(self.imageLabel)
        self.scrollArea.setAlignment(QtCore.Qt.AlignCenter)
                
        #---- Grid Set Up ----
                
        grid = QtGui.QGridLayout()
               
        grid.addWidget(self.scrollArea, 0, 0)
                
        grid.setSpacing(10)
        grid.setContentsMargins(0, 0, 0, 0) # (Left,Top, Right, Bottom)
        
        self.setLayout(grid)
        self.setWindowTitle("Image Viewer")
              
        #---- Create Initial Image with Matplotlib ----
        
        # http://stackoverflow.com/questions/17676373/
        # python-matplotlib-pyqt-copy-image-to-clipboard
        
        # http://stackoverflow.com/questions/21939658/
        # matplotlib-render-into-buffer-access-pixel-data
        
        figure = plt.figure()
        figure.patch.set_facecolor('white')

        figure_canvas = FigureCanvasQTAgg(figure)
        figure_canvas.draw()
                
        size = figure_canvas.size()
        width, height = size.width(), size.height()
        
        imgbuffer = figure_canvas.buffer_rgba()
        image = QtGui.QImage(imgbuffer, width, height,
                             QtGui.QImage.Format_ARGB32)
                             
        # Reference for the RGB to BGR swap:
        # http://sourceforge.net/p/matplotlib/mailman/message/5194542/
          
        image = QtGui.QImage.rgbSwapped(image)
        
        self.load_image(image, 0)
开发者ID:jpdrolet19,项目名称:WHAT,代码行数:67,代码来源:mplFigViewer.py

示例2: ImageViewer

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import buffer_rgba [as 别名]
    import sys

    app = QtGui.QApplication(sys.argv)
    imageViewer = ImageViewer()
    imageViewer.show()
    
    figure = plt.figure()
    figure.set_size_inches(11, 8.5)
    figure.patch.set_facecolor('white')
    plt.plot([1, 2, 3, 4], [1, 2, 3, 4], '-b')

    figure_canvas = FigureCanvasQTAgg(figure)
    figure_canvas.draw()
            
    size = figure_canvas.size()
    width, height = size.width(), size.height()
    print(width, height)
    print(figure_canvas.get_width_height())
    imgbuffer = figure_canvas.buffer_rgba()
    image = QtGui.QImage(imgbuffer, width, height,
                         QtGui.QImage.Format_ARGB32)
                         
    # Reference for the RGB to BGR swap:
    # http://sourceforge.net/p/matplotlib/mailman/message/5194542/
      
    image = QtGui.QImage.rgbSwapped(image)    
    imageViewer.load_image(image, 0)
    
    
    sys.exit(app.exec_())
开发者ID:jpdrolet19,项目名称:WHAT,代码行数:32,代码来源:mplFigViewer.py


注:本文中的matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.buffer_rgba方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。