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


Python Figure.canvas方法代码示例

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


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

示例1: make_figure

# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import canvas [as 别名]
def make_figure(*args, **kwargs):
    'Create an Agg figure for testing'
    from matplotlib.figure import Figure
    from matplotlib.backends.backend_agg import FigureCanvasAgg
    fig = Figure(*args, **kwargs)
    fig.canvas = FigureCanvasAgg(fig)
    return fig
开发者ID:ajoros,项目名称:MetPy,代码行数:9,代码来源:testing.py

示例2: save

# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import canvas [as 别名]
def save(filename, np_array, png=False):
    """ saves numpy array as bitmap and/or png image. A list of details
    may be included to save relevant info about the images in a CSV file
    of the same name. By default only a bitmap is produced.

    Parameters
    ----------

    filename : string
        Filename (without extension).

    np_array : numpy.array
        2D numpy array (dtype=uint8) representing grayscale image to save.

    png : bool
        By default, a bmp file is produced. If png=True, a png file will be
        retained along with the bitmap.
    """

    value_min = 0
    value_max = 255
    color_map = 'gray'

    fig = Figure(figsize=np_array.shape[::-1], dpi=1, frameon=False)
    fig.canvas = FigureCanvas(fig)
    fig.figimage(np_array, cmap=color_map, vmin=value_min,
                 vmax=value_max, origin=None)
    fig.savefig(filename, dpi=1, format=None)

    # save bitmap (convert from PNG)
    img = PIL.Image.open(filename + '.png')
    if len(img.split()) == 4:  # prevent IOError: cannot write mode RGBA as BMP
        r, g, b, a = img.split()
        img = PIL.Image.merge("RGB", (r, g, b))
    greyscale = img.convert("L")  # L indicates PIL's greyscale mode
    greyscale.save(filename + '.bmp')

    # delete PNG
    if not png:
        os.remove(filename + '.png')
开发者ID:AdamStone,项目名称:aberration,代码行数:42,代码来源:core.py

示例3: __init__

# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import canvas [as 别名]
    def __init__(self, parent=None, **kwargs):
        figsize = kwargs.pop('figsize', (3,3))
        dpi = kwargs.pop('dpi', 100)
        if 'limits' in kwargs:
            self._full_fov_lims = kwargs.pop('limits')
        extents = limits_to_extents(self._full_fov_lims)
        QtGui.QWidget.__init__(self, parent)
        # set up the Sag, Cor, Axi SliceFigures
        self.horizontalLayout = QtGui.QHBoxLayout(self)
        self.horizontalLayout.setObjectName("FigureLayout")


        # set axial figure
        fig = Figure(figsize=figsize, dpi=dpi)
        fig.canvas = Canvas(fig)
        Canvas.setSizePolicy(fig.canvas, QtGui.QSizePolicy.Expanding,
                             QtGui.QSizePolicy.Expanding)
        Canvas.updateGeometry(fig.canvas)
        fig.canvas.setParent(self)
        self.axi_fig = ssp.SliceFigure(fig, extents[AXI], blit=BLITTING)
        self.axi_fig.ax.set_xlabel('left to right', fontsize=8)
        self.axi_fig.ax.set_ylabel('posterior to anterior', fontsize=8)
        self.horizontalLayout.addWidget(fig.canvas)
        # set coronal figure
        fig = Figure(figsize=figsize, dpi=dpi)
        fig.canvas = Canvas(fig)
        Canvas.setSizePolicy(fig.canvas, QtGui.QSizePolicy.Expanding,
                             QtGui.QSizePolicy.Expanding)
        Canvas.updateGeometry(fig.canvas)
        fig.canvas.setParent(self)
        self.cor_fig = ssp.SliceFigure(fig, extents[COR], blit=BLITTING)
        self.cor_fig.ax.set_xlabel('left to right', fontsize=8)
        self.cor_fig.ax.set_ylabel('inferior to superior', fontsize=8)
        self.horizontalLayout.addWidget(fig.canvas)        
        # set sagittal figure
        fig = Figure(figsize=figsize, dpi=dpi)
        fig.canvas = Canvas(fig)
        Canvas.setSizePolicy(fig.canvas, QtGui.QSizePolicy.Expanding,
                             QtGui.QSizePolicy.Expanding)
        Canvas.updateGeometry(fig.canvas)
        fig.canvas.setParent(self)
        self.sag_fig = ssp.SliceFigure(fig, extents[SAG], blit=BLITTING)
        self.sag_fig.ax.set_xlabel('posterior to anterior', fontsize=8)
        self.sag_fig.ax.set_ylabel('inferior to superior', fontsize=8)        
        self.horizontalLayout.addWidget(fig.canvas)
        
        # put down figures in x, y, z order
        self.figs = [self.sag_fig, self.cor_fig, self.axi_fig]
        self.canvas_lookup = dict( ((f.canvas, f) for f in self.figs) )
        self._mouse_dragging = False
        # this should be something like a signal too, which can emit status
        self._xyz_position = [0,0,0]
        self._connect_events()

        self.setParent(parent)
        QtGui.QWidget.setSizePolicy(self, QtGui.QSizePolicy.Expanding,
                                    QtGui.QSizePolicy.Expanding)
        QtGui.QWidget.updateGeometry(self)
        self._main_plotted = False
        self.main_plots = []
        self._over_plotted = False
        self.over_plots = []
开发者ID:cindeem,项目名称:xipy,代码行数:64,代码来源:ortho_slices.py

示例4: setup_figure

# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import canvas [as 别名]
def setup_figure(*args, **kwargs):
    projection = kwargs.pop("projection","stereonet")
    fig = Figure(*args, **kwargs)
    fig.canvas = FigureCanvas(fig)
    ax = fig.add_subplot(111, projection=projection)
    return fig,ax
开发者ID:davenquinn,项目名称:Attitude,代码行数:8,代码来源:__init__.py

示例5: __init__

# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import canvas [as 别名]
    def __init__(self, loc_connections, image_connections,
                 image_props_connections, bbox,
                 functional_manager=None,
                 external_loc=None, parent=None, main_ref=None,
                 tfbeam=None, **kwargs):
        """
        Creates a new MplQT4TimeFreqWindow, which controls interaction
        with Nutmeg TFBeam objects. This window is a QT4TopLevelAuxiliaryWindow,
        giving it top level status. It contains:
         *a 2D image of the time-frequency plane with selectable bins (emits a
          functional image update event and a tf event, described below)
         *a TFBeam management panel, with data management and feature
          localizations (events described below)
         *a threshold management panel, to create different mask criteria

         Time-frequency point updates cause emission of the tf_point signal.
         To cause methods to be connected to this signal, include them in the
         tf_connections iterable argument. Methods will have this signature
         pattern:
         meth(timept, freq_a, freq_b)

         Overlay image updates are also signalled. To cause methods to be
         connected, include them in the image_connections iterable argument.
         Methods will have this signature pattern:
         meth(obj)
          * obj will give access to obj.overlay, obj.alpha,
          * obj.norm, obj.fill_value

         Spatial location updates cause emission of the xyz_point signal. To
         cause methods to be connected to this signal, include them in the
         loc_connections interable argument. Methods will have this signature
         pattern:
         meth(x, y, z)

         Parameters
         ----------
         loc_connections: iterable
             Methods to connect to the xyz_point signal
         image_connections: iterable
             Methods to connect to the new_image signal
         parent: QObject (optional)
             A QT4 QObject to set as the parent of this widget (thus causing
             this widget NOT to run as a top level window)
         main_ref: QObject (optional)
             A QT4 QObject to be considered as the "parent" of this widget,
             when this widget is running as a top level window
         tfbeam: TFBeam (optional)
             A TFBeam with which to preload the beam manager.
         **kwargs:
             figsize, dpi for the time-frequency plane figure
         """

        
        figsize = kwargs.pop('figsize', (6,4))
        dpi = kwargs.pop('dpi', 100)
        # insert some local callbacks into the connection lists
        image_connections = (self._update_from_new_overlay,) + \
                            image_connections
        image_props_connections = (self.update_tf_figure,) + \
                                  image_props_connections
        OverlayWindowInterface.__init__(self,
                                        loc_connections,
                                        image_connections,
                                        image_props_connections,
                                        bbox,
                                        external_loc=external_loc,
                                        parent=parent,
                                        main_ref=main_ref,
                                        functional_manager=functional_manager)

        # make sure that when the tfbeam manager's voxel index changes,
        # the tfplane image gets updated
        self.bvox_signal.connect(self.update_tf_figure)
        if functional_manager is None or \
           not isinstance(functional_manager, TFBeamManager):
            self.func_man = TFBeamManager(
                bbox, image_signal = self.image_changed,
                loc_signal = self.loc_changed,
                props_signal = self.image_props_changed,
                beam_vox_signal=self.bvox_signal
                )

        self.func_man.beam_vox_signal = self.bvox_signal
        
        vbox = QtGui.QVBoxLayout(self)

        # set up figure
        fig = Figure(figsize=figsize, dpi=dpi)
        fig.canvas = Canvas(fig)
        QtGui.QWidget.setSizePolicy(fig.canvas,
                                    QtGui.QSizePolicy.Expanding,
                                    QtGui.QSizePolicy.Expanding)
        Canvas.updateGeometry(fig.canvas)
        fig.canvas.setParent(self)
        self.fig = fig

        # fake plane at first
        self.tf_plane = self._initialize_tf_plane()
        vbox.addWidget(self.fig.canvas)

#.........这里部分代码省略.........
开发者ID:christandiono,项目名称:nutmeg-py,代码行数:103,代码来源:tfbeam_manager.py

示例6: plot_aligned

# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import canvas [as 别名]
def plot_aligned(pca, sparse=True, **kwargs):
    """ Plots the residuals of a principal component
        analysis of attiude data.
    """
    colormap = kwargs.pop('colormap',None)

    A = pca.rotated()
    # Flip the result if upside down
    if pca.normal[2] < 0:
        A[:,-1] *= -1
    minmax = [(A[:,i].min(),A[:,i].max()) for i in range(3)]
    lengths = [j-i for i,j in minmax]

    if sparse:
        i = 1
        l = len(A)
        if l > 10000:
            i = N.ceil(l/10000)
            A = A[::int(i)]

    log.info("Plotting with {} points".format(len(A)))

    w = 8
    ratio = (lengths[2]*2+lengths[1])/lengths[0]*1.5
    h = w*ratio
    if h < 3: h = 3

    r = (lengths[1]+5)/(lengths[2]+5)
    if r > 5:
        r = 5

    fig = Figure(figsize=(w,h))
    fig.canvas = FigureCanvas(fig)

    def setup_axes():
        gs = GridSpec(3,1, height_ratios=[r,1,1])
        kwargs = dict()
        axes = []
        for g in gs:
            ax = fig.add_subplot(g,**kwargs)
            kwargs['sharex'] = ax
            yield ax

    axes = list(setup_axes())

    fig.subplots_adjust(hspace=0, wspace=0.1)

    #lengths = attitude.pca.singular_values[::-1]

    titles = (
        "Plan view",
        "Long cross-section",
        "Short cross-section")

    ylabels = (
        "Meters",
        "Residuals (m)",
        "Residuals (m)")

    colors = ['cornflowerblue','red']

    hyp = sampling_axes(pca)
    vertical = vector(0,0,1)

    for title,ax,(a,b),ylabel in zip(titles,axes,
            [(0,1),(0,2),(1,2)],ylabels):

        kw = dict(linewidth=2, alpha=0.5)
        bounds = minmax[a]
        if b != 2:
            ax.plot(bounds,(0,0), c=colors[a], **kw)
            ax.plot((0,0),minmax[b], c=colors[b], **kw)
        else:
            ax.plot(bounds,(-10,-10), c=colors[a], **kw)
            v0 = N.zeros(3)
            v0[a] = 1
            axes = N.array([v0,vertical])

            ax_ = ([email protected](hyp)@axes.T).T
            ax_ = N.sqrt(ax_)
            l1 = N.linalg.norm(ax_[:-1])
            l2 = N.linalg.norm(ax_[-1])
            ang_error = 2*N.degrees(N.arctan2(l2,l1))

            title += ": {:.0f} m long, angular error (95% CI): {:.2f}º".format(lengths[a], ang_error)

            bounds = minmax[0]
            x_ = N.linspace(bounds[0]*1.2,bounds[1]*1.2,100)

            err = HyperbolicErrors(hyp,x_,axes=axes)
            err.plot(ax, fc='#cccccc', alpha=0.3)

        x,y = A[:,a], A[:,b]
        kw = dict(alpha=0.5, zorder=5)

        if colormap is None:
            ax.plot(x,y,c="#555555", linestyle='None', marker='.',**kw)
        else:
            ax.scatter(x,y,c=A[:,-1], cmap=colormap, **kw)

#.........这里部分代码省略.........
开发者ID:davenquinn,项目名称:Attitude,代码行数:103,代码来源:pca_aligned.py


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