• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python transforms.IdentityTransform类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中matplotlib.transforms.IdentityTransform的典型用法代码示例。如果您正苦于以下问题:Python IdentityTransform类的具体用法?Python IdentityTransform怎么用?Python IdentityTransform使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: _draw_unsampled_image

    def _draw_unsampled_image(self, renderer, gc):
        """
        draw unsampled image. The renderer should support a draw_image method
        with scale parameter.
        """
        trans = self.get_transform()  # axes.transData

        # convert the coordinates to the intermediate coordinate (ic).
        # The transformation from the ic to the canvas is a pure
        # affine transform.

        # A straight-forward way is to use the non-affine part of the
        # original transform for conversion to the ic.

        # firs, convert the image extent to the ic
        x_llc, x_trc, y_llc, y_trc = self.get_extent()

        xy = trans.transform(np.array([(x_llc, y_llc),
                                       (x_trc, y_trc)]))

        _xx1, _yy1 = xy[0]
        _xx2, _yy2 = xy[1]

        extent_in_ic = _xx1, _xx2, _yy1, _yy2

        # define trans_ic_to_canvas : unless _image_skew_coordinate is
        # set, it is simply a affine part of the original transform.
        if self._image_skew_coordinate:
            # skew the image when required.
            x_lrc, y_lrc = self._image_skew_coordinate
            xy2 = trans.transform(np.array([(x_lrc, y_lrc)]))
            _xx3, _yy3 = xy2[0]

            tr_rotate_skew = self._get_rotate_and_skew_transform(_xx1, _yy1,
                                                                 _xx2, _yy2,
                                                                 _xx3, _yy3)
            trans_ic_to_canvas = tr_rotate_skew
        else:
            trans_ic_to_canvas = IdentityTransform()

        # Now, viewLim in the ic.  It can be rotated and can be
        # skewed. Make it big enough.
        x1, y1, x2, y2 = self.axes.bbox.extents
        trans_canvas_to_ic = trans_ic_to_canvas.inverted()
        xy_ = trans_canvas_to_ic.transform(np.array([(x1, y1),
                                                     (x2, y1),
                                                     (x2, y2),
                                                     (x1, y2)]))
        x1_, x2_ = min(xy_[:, 0]), max(xy_[:, 0])
        y1_, y2_ = min(xy_[:, 1]), max(xy_[:, 1])
        viewLim_in_ic = Bbox.from_extents(x1_, y1_, x2_, y2_)

        # get the image, sliced if necessary. This is done in the ic.
        im, xmin, ymin, dxintv, dyintv, sx, sy = \
            self._get_unsampled_image(self._A, extent_in_ic, viewLim_in_ic)

        if im is None:
            return  # I'm not if this check is required. -JJL

        fc = self.axes.patch.get_facecolor()
        bg = mcolors.colorConverter.to_rgba(fc, 0)
        im.set_bg(*bg)

        # image input dimensions
        im.reset_matrix()
        numrows, numcols = im.get_size()

        if numrows <= 0 or numcols <= 0:
            return
        im.resize(numcols, numrows)  # just to create im.bufOut that
                                     # is required by backends. There
                                     # may be better solution -JJL

        im._url = self.get_url()
        im._gid = self.get_gid()

        renderer.draw_image(gc, xmin, ymin, im, dxintv, dyintv,
                            trans_ic_to_canvas)
开发者ID:SungSingSong,项目名称:matplotlib,代码行数:78,代码来源:image.py


示例2: _make_image

    def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
                    unsampled=False, round_to_pixel_border=True):
        """
        Normalize, rescale and color the image `A` from the given
        in_bbox (in data space), to the given out_bbox (in pixel
        space) clipped to the given clip_bbox (also in pixel space),
        and magnified by the magnification factor.

        `A` may be a greyscale image (MxN) with a dtype of `float32`,
        `float64`, `uint16` or `uint8`, or an RGBA image (MxNx4) with
        a dtype of `float32`, `float64`, or `uint8`.

        If `unsampled` is True, the image will not be scaled, but an
        appropriate affine transformation will be returned instead.

        If `round_to_pixel_border` is True, the output image size will
        be rounded to the nearest pixel boundary.  This makes the
        images align correctly with the axes.  It should not be used
        in cases where you want exact scaling, however, such as
        FigureImage.

        Returns the resulting (image, x, y, trans), where (x, y) is
        the upper left corner of the result in pixel space, and
        `trans` is the affine transformation from the image to pixel
        space.
        """
        if A is None:
            raise RuntimeError('You must first set the image'
                               ' array or the image attribute')

        clipped_bbox = Bbox.intersection(out_bbox, clip_bbox)

        if clipped_bbox is None:
            return None, 0, 0, None

        out_width_base = clipped_bbox.width * magnification
        out_height_base = clipped_bbox.height * magnification

        if out_width_base == 0 or out_height_base == 0:
            return None, 0, 0, None

        if self.origin == 'upper':
            # Flip the input image using a transform.  This avoids the
            # problem with flipping the array, which results in a copy
            # when it is converted to contiguous in the C wrapper
            t0 = Affine2D().translate(0, -A.shape[0]).scale(1, -1)
        else:
            t0 = IdentityTransform()

        t0 += (
            Affine2D()
            .scale(
                in_bbox.width / A.shape[1],
                in_bbox.height / A.shape[0])
            .translate(in_bbox.x0, in_bbox.y0)
            + self.get_transform())

        t = (t0
             + Affine2D().translate(
                 -clipped_bbox.x0,
                 -clipped_bbox.y0)
             .scale(magnification, magnification))

        # So that the image is aligned with the edge of the axes, we want
        # to round up the output width to the next integer.  This also
        # means scaling the transform just slightly to account for the
        # extra subpixel.
        if (t.is_affine and round_to_pixel_border and
                (out_width_base % 1.0 != 0.0 or out_height_base % 1.0 != 0.0)):
            out_width = int(ceil(out_width_base))
            out_height = int(ceil(out_height_base))
            extra_width = (out_width - out_width_base) / out_width_base
            extra_height = (out_height - out_height_base) / out_height_base
            t += Affine2D().scale(
                1.0 + extra_width, 1.0 + extra_height)
        else:
            out_width = int(out_width_base)
            out_height = int(out_height_base)

        if not unsampled:
            created_rgba_mask = False

            if A.ndim not in (2, 3):
                raise ValueError("Invalid dimensions, got %s" % (A.shape,))

            if A.ndim == 2:
                A = self.norm(A)
                if A.dtype.kind == 'f':
                    # If the image is greyscale, convert to RGBA and
                    # use the extra channels for resizing the over,
                    # under, and bad pixels.  This is needed because
                    # Agg's resampler is very aggressive about
                    # clipping to [0, 1] and we use out-of-bounds
                    # values to carry the over/under/bad information
                    rgba = np.empty((A.shape[0], A.shape[1], 4), dtype=A.dtype)
                    rgba[..., 0] = A  # normalized data
                    # this is to work around spurious warnings coming
                    # out of masked arrays.
                    with np.errstate(invalid='ignore'):
                        rgba[..., 1] = A < 0  # under data
#.........这里部分代码省略.........
开发者ID:sandragyaguez,项目名称:MetricasFormales,代码行数:101,代码来源:image.py


示例3: _make_image

    def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
                    unsampled=False, round_to_pixel_border=True):
        """
        Normalize, rescale and color the image `A` from the given
        in_bbox (in data space), to the given out_bbox (in pixel
        space) clipped to the given clip_bbox (also in pixel space),
        and magnified by the magnification factor.

        `A` may be a greyscale image (MxN) with a dtype of `float32`,
        `float64`, `uint16` or `uint8`, or an RGBA image (MxNx4) with
        a dtype of `float32`, `float64`, or `uint8`.

        If `unsampled` is True, the image will not be scaled, but an
        appropriate affine transformation will be returned instead.

        If `round_to_pixel_border` is True, the output image size will
        be rounded to the nearest pixel boundary.  This makes the
        images align correctly with the axes.  It should not be used
        in cases where you want exact scaling, however, such as
        FigureImage.

        Returns the resulting (image, x, y, trans), where (x, y) is
        the upper left corner of the result in pixel space, and
        `trans` is the affine transformation from the image to pixel
        space.
        """
        if A is None:
            raise RuntimeError('You must first set the image'
                               ' array or the image attribute')

        clipped_bbox = Bbox.intersection(out_bbox, clip_bbox)

        if clipped_bbox is None:
            return None, 0, 0, None

        out_width_base = clipped_bbox.width * magnification
        out_height_base = clipped_bbox.height * magnification

        if out_width_base == 0 or out_height_base == 0:
            return None, 0, 0, None

        if self.origin == 'upper':
            # Flip the input image using a transform.  This avoids the
            # problem with flipping the array, which results in a copy
            # when it is converted to contiguous in the C wrapper
            t0 = Affine2D().translate(0, -A.shape[0]).scale(1, -1)
        else:
            t0 = IdentityTransform()

        t0 += (
            Affine2D()
            .scale(
                in_bbox.width / A.shape[1],
                in_bbox.height / A.shape[0])
            .translate(in_bbox.x0, in_bbox.y0)
            + self.get_transform())

        t = (t0
             + Affine2D().translate(
                 -clipped_bbox.x0,
                 -clipped_bbox.y0)
             .scale(magnification, magnification))

        # So that the image is aligned with the edge of the axes, we want
        # to round up the output width to the next integer.  This also
        # means scaling the transform just slightly to account for the
        # extra subpixel.
        if (t.is_affine and round_to_pixel_border and
            (out_width_base % 1.0 != 0.0 or
             out_height_base % 1.0 != 0.0)):
            out_width = int(ceil(out_width_base) + 1)
            out_height = int(ceil(out_height_base) + 1)
            extra_width = (out_width - out_width_base) / out_width_base
            extra_height = (out_height - out_height_base) / out_height_base
            t += Affine2D().scale(
                1.0 + extra_width, 1.0 + extra_height)
        else:
            out_width = int(out_width_base)
            out_height = int(out_height_base)

        if not unsampled:
            created_rgba_mask = False

            if A.ndim == 2:
                A = self.norm(A)
                # If the image is greyscale, convert to RGBA with the
                # correct alpha channel for resizing
                rgba = np.empty((A.shape[0], A.shape[1], 4), dtype=A.dtype)
                rgba[..., 0:3] = np.expand_dims(A, 2)
                if A.dtype.kind == 'f':
                    rgba[..., 3] = ~A.mask
                else:
                    rgba[..., 3] = np.where(A.mask, 0, np.iinfo(A.dtype).max)
                A = rgba
                output = np.zeros((out_height, out_width, 4), dtype=A.dtype)
                alpha = 1.0
                created_rgba_mask = True
            elif A.ndim == 3:
                # Always convert to RGBA, even if only RGB input
                if A.shape[2] == 3:
#.........这里部分代码省略.........
开发者ID:Perados,项目名称:matplotlib,代码行数:101,代码来源:image.py


示例4: _make_image_special

    def _make_image_special(self, A, density, in_bbox, out_bbox, clip_bbox, magnification=1.0,
                    unsampled=False, round_to_pixel_border=True, densities=None):
        """
        This function is a copy of _ImageBase._make_image(*args, **kwargs), but with only the A.ndim == 2 case,
        and with the transformation of the alpha channel on top of the normal behaviour with the colormap's RGBA
        """

        if A is None:
            raise RuntimeError('You must first set the image '
                               'array or the image attribute')
        if A.size == 0:
            raise RuntimeError("_make_image must get a non-empty image. "
                               "Your Artist's draw method must filter before "
                               "this method is called.")

        clipped_bbox = Bbox.intersection(out_bbox, clip_bbox)

        if clipped_bbox is None:
            return None, 0, 0, None

        out_width_base = clipped_bbox.width * magnification
        out_height_base = clipped_bbox.height * magnification

        if out_width_base == 0 or out_height_base == 0:
            return None, 0, 0, None

        if self.origin == 'upper':
            # Flip the input image using a transform.  This avoids the
            # problem with flipping the array, which results in a copy
            # when it is converted to contiguous in the C wrapper
            t0 = Affine2D().translate(0, -A.shape[0]).scale(1, -1)
        else:
            t0 = IdentityTransform()

        t0 += (
                Affine2D()
                .scale(
                    in_bbox.width / A.shape[1],
                    in_bbox.height / A.shape[0])
                .translate(in_bbox.x0, in_bbox.y0)
                + self.get_transform())

        t = (t0
             + Affine2D().translate(
                    -clipped_bbox.x0,
                    -clipped_bbox.y0)
             .scale(magnification, magnification))

        # So that the image is aligned with the edge of the axes, we want
        # to round up the output width to the next integer.  This also
        # means scaling the transform just slightly to account for the
        # extra subpixel.
        if (t.is_affine and round_to_pixel_border and
                (out_width_base % 1.0 != 0.0 or out_height_base % 1.0 != 0.0)):
            out_width = int(ceil(out_width_base))
            out_height = int(ceil(out_height_base))
            extra_width = (out_width - out_width_base) / out_width_base
            extra_height = (out_height - out_height_base) / out_height_base
            t += Affine2D().scale(1.0 + extra_width, 1.0 + extra_height)
        else:
            out_width = int(out_width_base)
            out_height = int(out_height_base)

        if not unsampled:
            #if A.ndim not in (2, 3):
            #    raise ValueError("Invalid dimensions, got {}".format(A.shape))

            # if we are a 2D array, then we are running through the
            # norm + colormap transformation.  However, in general the
            # input data is not going to match the size on the screen so we
            # have to resample to the correct number of pixels
            # need to

            # TODO slice input array first
            inp_dtype = A.dtype
            a_min = A.min()
            a_max = A.max()
            # figure out the type we should scale to.  For floats,
            # leave as is.  For integers cast to an appropriate-sized
            # float.  Small integers get smaller floats in an attempt
            # to keep the memory footprint reasonable.
            if a_min is np.ma.masked:
                # all masked, so values don't matter
                a_min, a_max = np.int32(0), np.int32(1)
            if inp_dtype.kind == 'f':
                scaled_dtype = A.dtype
            else:
                # probably an integer of some type.
                da = a_max.astype(np.float64) - a_min.astype(np.float64)
                if da > 1e8:
                    # give more breathing room if a big dynamic range
                    scaled_dtype = np.float64
                else:
                    scaled_dtype = np.float32

            # scale the input data to [.1, .9].  The Agg
            # interpolators clip to [0, 1] internally, use a
            # smaller input scale to identify which of the
            # interpolated points need to be should be flagged as
            # over / under.
#.........这里部分代码省略.........
开发者ID:SKIRT,项目名称:PTS,代码行数:101,代码来源:scatter_density.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python transforms.ScaledTranslation类代码示例发布时间:2022-05-27
下一篇:
Python transforms.BboxTransformFrom类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap