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


Python FigureCanvasAgg.get_width_height方法代码示例

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


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

示例1: _fig_to_array

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_width_height [as 别名]
 def _fig_to_array(self, fig):
   """
   Convert matplotlib figure to an image (numpy array)
   """
   fig.canvas.draw()  # Updates
   canvas = FigureCanvasAgg(fig)
   buf = canvas.tostring_rgb()
   w, h = canvas.get_width_height()
   return np.fromstring(buf, dtype=np.uint8).reshape(h, w, 3)
开发者ID:amill676,项目名称:realtime_audio,代码行数:11,代码来源:vidwriter.py

示例2: export_close_figure

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_width_height [as 别名]
 def export_close_figure(self, fobject):
     """
     Export as a string and close the figure.
     """
     canvas = FigureCanvasAgg(fobject)
     canvas.draw()
     size, buf = canvas.get_width_height(), canvas.tostring_rgb()
     #close and return data
     close()
     return size, buf
开发者ID:eaudeweb,项目名称:naaya,代码行数:12,代码来源:drawCharts.py

示例3: set_plot_state

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_width_height [as 别名]
    def set_plot_state(self, extra_high=False, extra_low=False):
        """
        Build image state that wx.html understand
        by plotting, putting it into wx.FileSystem image object

        : extrap_high,extra_low: low/high extrapolations
        are possible extra-plots
        """
        # some imports
        import wx
        import matplotlib.pyplot as plt
        from matplotlib.backends.backend_agg import FigureCanvasAgg

        # we use simple plot, not plotpanel
        # make matlab figure
        fig = plt.figure()
        fig.set_facecolor('w')
        graph = fig.add_subplot(111)

        # data plot
        graph.errorbar(self.data.x, self.data.y, yerr=self.data.dy, fmt='o')
        # low Q extrapolation fit plot
        if not extra_low == 'False':
            graph.plot(self.theory_lowQ.x, self.theory_lowQ.y)
        # high Q extrapolation fit plot
        if not extra_high == 'False':
            graph.plot(self.theory_highQ.x, self.theory_highQ.y)
        graph.set_xscale("log", nonposx='clip')
        graph.set_yscale("log", nonposy='clip')
        graph.set_xlabel('$\\rm{Q}(\\AA^{-1})$', fontsize=12)
        graph.set_ylabel('$\\rm{Intensity}(cm^{-1})$', fontsize=12)
        canvas = FigureCanvasAgg(fig)
        # actually make image
        canvas.draw()

        # make python.Image object
        # size
        w, h = canvas.get_width_height()
        # convert to wx.Image
        wximg = wx.EmptyImage(w, h)
        # wxim.SetData(img.convert('RGB').tostring() )
        wximg.SetData(canvas.tostring_rgb())
        # get the dynamic image for the htmlwindow
        wximgbmp = wx.BitmapFromImage(wximg)
        # store the image in wx.FileSystem Object
        wx.FileSystem.AddHandler(wx.MemoryFSHandler())
        # use wx.MemoryFSHandler
        self.imgRAM = wx.MemoryFSHandler()
        # AddFile, image can be retrieved with 'memory:filename'
        self.imgRAM.AddFile('img_inv.png', wximgbmp, wx.BITMAP_TYPE_PNG)

        self.wximgbmp = 'memory:img_inv.png'
        self.image = fig
开发者ID:ianhi,项目名称:sasview,代码行数:55,代码来源:invariant_state.py

示例4: _animate

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_width_height [as 别名]
    def _animate(self, frames, func, **animArgs):
        if self._outputParam is None: raise NotImplemented

        images = []
        figure = plt.Figure(figsize=(6,6), dpi=300, facecolor='w')
        axes = figure.add_subplot(111)
        canvas = FigureCanvasAgg(figure) 

        for frame in frames:
            axes.clear()
            func(frame, axes)
            canvas.draw()
            
            image = np.fromstring(canvas.tostring_rgb(), dtype=np.uint8)
            image.shape = canvas.get_width_height() + (3,)
            images.append(image)
        self._render(images)
开发者ID:chase-ok,项目名称:OlinStreamingRefresh,代码行数:19,代码来源:visual.py

示例5: get_image

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_width_height [as 别名]
    def get_image(self):
        width = self.extent[1] - self.extent[0]
        height = self.extent[3] - self.extent[2]
        self.figure.set_size_inches((6, 6. * width / height))
        self.figure.set_dpi(self.settings.exportDpi)
        self.figure.patch.set_alpha(0)
        self.axes.axesPatch.set_alpha(0)
        canvas = FigureCanvasAgg(self.figure)
        canvas.draw()

        renderer = canvas.get_renderer()
        if matplotlib.__version__ >= '1.2':
            buf = renderer.buffer_rgba()
        else:
            buf = renderer.buffer_rgba(0, 0)
        size = canvas.get_width_height()
        image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)

        return image
开发者ID:EarToEarOak,项目名称:RTLSDR-Scanner,代码行数:21,代码来源:dialogs_file.py

示例6: figure_to_pixmap

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_width_height [as 别名]
def figure_to_pixmap(figure):
    """Get a pixmap from a headless MPL figure
    :param figure: a headless (or any other) matplotlib figure object
    :type filename: matplotlib.figure.Figure
    :returns: 3D numpy uint8 array of pixel values (the image)
    """
    canvas = FigureCanvasAgg(figure)
    canvas.draw()
    w, h = canvas.get_width_height()
    pixmap_string = canvas.tostring_argb()
    #line up the channels right
    pix_array = np.fromstring(pixmap_string, dtype=np.uint8)
    pix_array.shape = (w, h, 4)
    # pix_array = pix_array[:, :, ::-1]
    swapped_array = np.zeros(pix_array.shape, dtype=np.uint8)
    swapped_array[:,:,3] = pix_array[:,:,0]
    swapped_array[:,:,0] = pix_array[:,:,1]
    swapped_array[:,:,1] = pix_array[:,:,2]
    swapped_array[:,:,2] = pix_array[:,:,3]
    return swapped_array
开发者ID:NICTA,项目名称:fsdf-hackfest,代码行数:22,代码来源:headlessmpl.py

示例7: export_image

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_width_height [as 别名]
def export_image(filename, format, figure):
    oldSize = figure.get_size_inches()
    oldDpi = figure.get_dpi()
    figure.set_size_inches((8, 4.5))
    figure.set_dpi(600)

    canvas = FigureCanvasAgg(figure)
    canvas.draw()
    renderer = canvas.get_renderer()
    if matplotlib.__version__ >= '1.2':
        buf = renderer.buffer_rgba()
    else:
        buf = renderer.buffer_rgba(0, 0)
    size = canvas.get_width_height()
    image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
    image = image.convert('RGB')
    ext = File.get_export_ext(format, File.Exports.IMAGE)
    image.save(filename, format=ext[1::])

    figure.set_size_inches(oldSize)
    figure.set_dpi(oldDpi)
开发者ID:BloodyCool,项目名称:RTLSDR-Scanner,代码行数:23,代码来源:file.py

示例8: __draw_image

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_width_height [as 别名]
    def __draw_image(self, sizeInches, ppi):
        oldSize = self.figure.get_size_inches()
        oldDpi = self.figure.get_dpi()
        self.figure.set_size_inches(sizeInches)
        self.figure.set_dpi(ppi)

        canvas = FigureCanvasAgg(self.figure)
        canvas.draw()
        renderer = canvas.get_renderer()
        if matplotlib.__version__ >= '1.2':
            buf = renderer.buffer_rgba()
        else:
            buf = renderer.buffer_rgba(0, 0)
        size = canvas.get_width_height()
        image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)

        self.figure.set_size_inches(oldSize)
        self.figure.set_dpi(oldDpi)

        imageWx = wx.EmptyImage(image.size[0], image.size[1])
        imageWx.SetData(image.convert('RGB').tostring())

        return imageWx
开发者ID:PatMart,项目名称:RTLSDR-Scanner,代码行数:25,代码来源:printer.py

示例9: _animate

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_width_height [as 别名]
    def _animate(self, frames, func, **animArgs):
        if self._outputParam is None:
            raise NotImplemented
        figure = plt.Figure(figsize=(6, 6), dpi=300, facecolor="w")
        axes = figure.add_subplot(111)
        canvas = FigureCanvasAgg(figure)
        chunks = 10
        multiframes = [frames[i : i + chunks] for i in xrange(0, len(frames), chunks)]
        count = 0
        for frames in multiframes:
            count += 1
            images = []
            for frame in frames:
                axes.clear()
                func(frame, axes)
                canvas.draw()

                image = np.fromstring(canvas.tostring_rgb(), dtype=np.uint8)
                image.shape = canvas.get_width_height() + (3,)
                images.append(image)
            self._render(images, num=str(count))
        if count > 1:
            self._joinParts(count)
开发者ID:RyanEggert,项目名称:Research-CollectiveMotion,代码行数:25,代码来源:visual.py

示例10: if

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_width_height [as 别名]
while disp.isNotDone():
    ax = fig.gca(projection='3d')
    ax.set_xlabel('BLUE', color=(0,0,1) )
    ax.set_ylabel('GREEN',color=(0,1,0))
    ax.set_zlabel('RED',color=(1,0,0))
    # Get the color histogram
    img = cam.getImage().scale(0.3)
    rgb = img.getNumpyCv2()
    hist = cv2.calcHist([rgb],[0,1,2],None,[bins,bins,bins],[0,256,0,256,0,256])
    hist = hist/np.max(hist)
    # render everything
    [ ax.plot([x],[y],[z],'.',markersize=max(hist[x,y,z]*100,6),color=color) for x,y,z,color in idxs if(hist[x][y][z]>0) ]
    #[ ax.plot([x],[y],[z],'.',color=color) for x,y,z,color in idxs if(hist[x][y][z]>0) ]
    ax.set_xlim3d(0, bins-1)
    ax.set_ylim3d(0, bins-1)
    ax.set_zlim3d(0, bins-1)
    azim = (azim+0.5)%360
    ax.view_init(elev=35, azim=azim)
    ########### convert matplotlib to  SimpleCV image
    canvas.draw()
    renderer = canvas.get_renderer()
    raw_data = renderer.tostring_rgb()
    size = canvas.get_width_height()    
    surf = pg.image.fromstring(raw_data, size, "RGB")
    figure = Image(surf)
    ############ All done
    figure = figure.floodFill((0,0), tolerance=5,color=Color.WHITE)
    result = figure.blit(img, pos=(20,20))
    result.save(disp)
    fig.clf()
开发者ID:AndersonYangOh,项目名称:SimpleCV,代码行数:32,代码来源:ColorCube.py

示例11: gen_land_bitmap

# 需要导入模块: from matplotlib.backends.backend_agg import FigureCanvasAgg [as 别名]
# 或者: from matplotlib.backends.backend_agg.FigureCanvasAgg import get_width_height [as 别名]
 def gen_land_bitmap(bmap, resolution_meters):
             
     #Get land polygons and bbox of polygons
     polys = []
     xmin = np.finfo(np.float64).max
     xmax = -np.finfo(np.float64).max
     ymin = xmin
     ymax = xmax
             
     logging.debug('Rasterizing Basemap, number of land polys: ' + str(len(bmap.landpolygons)))
     # If no polys: return a zero map
     if (len(bmap.landpolygons) == 0):
         raise Exception('Basemap contains no land polys to rasterize')
     
     for polygon in bmap.landpolygons:
         coords = polygon.get_coords()
         xmin = min(xmin, np.min(coords[:,0]))
         xmax = max(xmax, np.max(coords[:,0]))
         ymin = min(ymin, np.min(coords[:,1]))
         ymax = max(ymax, np.max(coords[:,1]))
         polys.append(coords)
         
     xmin = np.floor(xmin/resolution_meters)*resolution_meters
     xmax = np.ceil(xmax/resolution_meters)*resolution_meters
     ymin = np.floor(ymin/resolution_meters)*resolution_meters
     ymax = np.ceil(ymax/resolution_meters)*resolution_meters
     
     # For debugging
     logging.debug('Rasterizing Basemap, bounding box: ' + str([xmin, xmax, ymin, ymax]))
     
     # Switch backend to prevent creating an empty figure in notebook
     orig_backend = plt.get_backend()
     plt.switch_backend('agg')
     
     # Create figure to help rasterize
     fig = plt.figure(frameon=False)
     ax = plt.Axes(fig, [0., 0., 1., 1.])
     ax.set_axis_off()
     fig.add_axes(ax)   
     ax.set_xlim(xmin, xmax)
     ax.set_ylim(ymin, ymax)
     
     # Set aspect and resolution
     # Aspect gives 1 in high plot
     aspect = (xmax-xmin)/(ymax-ymin)
     resolution_dpi = (ymax-ymin) / resolution_meters
     
     fig.set_dpi(resolution_dpi)
     fig.set_size_inches(aspect, 1)
     
     # Add polygons
     lc = PolyCollection(polys, facecolor='k', lw=0)
     ax.add_collection(lc)
     
     # Create canvas and rasterize
     canvas = FigureCanvasAgg(fig)
     try:
         canvas.draw()
         width, height = canvas.get_width_height()
         rgb_data = np.fromstring(canvas.tostring_rgb(), dtype='uint8').reshape(height, width, 3)
         data = rgb_data[:,:,1]
         plt.close(fig) #comment this for debugging purposes and replace with plt.show()
         logging.debug('Rasterized size: ' + str([width, height]))
     except MemoryError:
         gc.collect()
         raise Exception('Basemap rasterized size too large: ' 
                         + str(aspect*resolution_dpi) + '*' + str(resolution_dpi) 
                         + ' cells')
     finally:
         # Reset backend
         plt.switch_backend(orig_backend)
     
     
     return RasterizedBasemap(xmin, xmax, ymin, ymax, resolution_meters, data)
开发者ID:p1heidary,项目名称:opendrift,代码行数:76,代码来源:reader_basemap_landmask.py


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