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

Python cbook.restrict_dict函数代码示例

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

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



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

示例1: test_restrict_dict

def test_restrict_dict():
    d = {'foo': 'bar', 1: 2}
    d1 = cbook.restrict_dict(d, ['foo', 1])
    assert d1 == d
    d2 = cbook.restrict_dict(d, ['bar', 2])
    assert d2 == {}
    d3 = cbook.restrict_dict(d, {'foo': 1})
    assert d3 == {'foo': 'bar'}
    d4 = cbook.restrict_dict(d, {})
    assert d4 == {}
    d5 = cbook.restrict_dict(d, {'foo', 2})
    assert d5 == {'foo': 'bar'}
    # check that d was not modified
    assert d == {'foo': 'bar', 1: 2}
开发者ID:AlexandreAbraham,项目名称:matplotlib,代码行数:14,代码来源:test_cbook.py


示例2: test_restrict_dict

def test_restrict_dict():
    d = {'foo': 'bar', 1: 2}
    d1 = cbook.restrict_dict(d, ['foo', 1])
    assert_equal(d1, d)
    d2 = cbook.restrict_dict(d, ['bar', 2])
    assert_equal(d2, {})
    d3 = cbook.restrict_dict(d, {'foo': 1})
    assert_equal(d3, {'foo': 'bar'})
    d4 = cbook.restrict_dict(d, {})
    assert_equal(d4, {})
    d5 = cbook.restrict_dict(d, set(['foo', 2]))
    assert_equal(d5, {'foo': 'bar'})
    # check that d was not modified
    assert_equal(d, {'foo': 'bar', 1: 2})
开发者ID:AudiencePropensities,项目名称:matplotlib,代码行数:14,代码来源:test_cbook.py


示例3: print_jpg

        def print_jpg(self, filename_or_obj, *args, **kwargs):
            """
            Supported kwargs:

            *quality*: The image quality, on a scale from 1 (worst) to
                95 (best). The default is 95, if not given in the
                matplotlibrc file in the savefig.jpeg_quality parameter.
                Values above 95 should be avoided; 100 completely
                disables the JPEG quantization stage.

            *optimize*: If present, indicates that the encoder should
                make an extra pass over the image in order to select
                optimal encoder settings.

            *progressive*: If present, indicates that this image
                should be stored as a progressive JPEG file.
            """
            buf, size = self.print_to_buffer()
            if kwargs.pop("dryrun", False):
                return
            image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
            options = restrict_dict(kwargs, ['quality', 'optimize',
                                             'progressive'])

            if 'quality' not in options:
                options['quality'] = rcParams['savefig.jpeg_quality']

            return image.save(filename_or_obj, format='jpeg', **options)
开发者ID:7924102,项目名称:matplotlib,代码行数:28,代码来源:backend_agg.py


示例4: print_jpg

        def print_jpg(self, filename_or_obj, *args, **kwargs):
            """
            Supported kwargs:

            *quality*: The image quality, on a scale from 1 (worst) to
                95 (best). The default is 95, if not given in the
                matplotlibrc file in the savefig.jpeg_quality parameter.
                Values above 95 should be avoided; 100 completely
                disables the JPEG quantization stage.

            *optimize*: If present, indicates that the encoder should
                make an extra pass over the image in order to select
                optimal encoder settings.

            *progressive*: If present, indicates that this image
                should be stored as a progressive JPEG file.
            """
            buf, size = self.print_to_buffer()
            if kwargs.pop("dryrun", False):
                return
            # The image is "pasted" onto a white background image to safely
            # handle any transparency
            image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
            color = mcolors.colorConverter.to_rgb(
                rcParams.get('savefig.facecolor', 'white'))
            color = tuple([int(x * 255.0) for x in color])
            background = Image.new('RGB', size, color)
            background.paste(image, image)
            options = restrict_dict(kwargs, ['quality', 'optimize',
                                             'progressive'])

            if 'quality' not in options:
                options['quality'] = rcParams['savefig.jpeg_quality']

            return background.save(filename_or_obj, format='jpeg', **options)
开发者ID:Jajauma,项目名称:dotfiles,代码行数:35,代码来源:backend_agg.py


示例5: test_restrict_dict

def test_restrict_dict():
    d = {'foo': 'bar', 1: 2}
    with pytest.warns(cbook.deprecation.MatplotlibDeprecationWarning) as rec:
        d1 = cbook.restrict_dict(d, ['foo', 1])
        assert d1 == d
        d2 = cbook.restrict_dict(d, ['bar', 2])
        assert d2 == {}
        d3 = cbook.restrict_dict(d, {'foo': 1})
        assert d3 == {'foo': 'bar'}
        d4 = cbook.restrict_dict(d, {})
        assert d4 == {}
        d5 = cbook.restrict_dict(d, {'foo', 2})
        assert d5 == {'foo': 'bar'}
    assert len(rec) == 5
    # check that d was not modified
    assert d == {'foo': 'bar', 1: 2}
开发者ID:dpritsos,项目名称:TeCA,代码行数:16,代码来源:test_cbook.py


示例6: _print_image

    def _print_image(self, filename, format, *args, **kwargs):
        if self.flags() & gtk.REALIZED == 0:
            # for self.window(for pixmap) and has a side effect of altering
            # figure width,height (via configure-event?)
            gtk.DrawingArea.realize(self)

        width, height = self.get_width_height()
        pixmap = gdk.Pixmap(self.window, width, height)
        self._renderer.set_pixmap(pixmap)
        self._render_figure(pixmap, width, height)

        # jpg colors don't match the display very well, png colors match
        # better
        pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, 0, 8, width, height)
        pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(), 0, 0, 0, 0, width, height)

        # set the default quality, if we are writing a JPEG.
        # http://www.pygtk.org/docs/pygtk/class-gdkpixbuf.html#method-gdkpixbuf--save
        options = cbook.restrict_dict(kwargs, ["quality"])
        if format in ["jpg", "jpeg"]:
            if "quality" not in options:
                options["quality"] = rcParams["savefig.jpeg_quality"]

            options["quality"] = str(options["quality"])

        if is_string_like(filename):
            try:
                pixbuf.save(filename, format, options=options)
            except gobject.GError as exc:
                error_msg_gtk("Save figure failure:\n%s" % (exc,), parent=self)
        elif is_writable_file_like(filename):
            if hasattr(pixbuf, "save_to_callback"):

                def save_callback(buf, data=None):
                    data.write(buf)

                try:
                    pixbuf.save_to_callback(save_callback, format, user_data=filename, options=options)
                except gobject.GError as exc:
                    error_msg_gtk("Save figure failure:\n%s" % (exc,), parent=self)
            else:
                raise ValueError("Saving to a Python file-like object is only supported by PyGTK >= 2.8")
        else:
            raise ValueError("filename must be a path or a file-like object")
开发者ID:petebachant,项目名称:matplotlib,代码行数:44,代码来源:backend_gtk.py


示例7: _print_image

    def _print_image(self, filename, format, *args, **kwargs):
        width, height = self.get_width_height()
        pixmap = gtk.gdk.Pixmap(None, width, height, depth=24)
        self._render_figure(pixmap, width, height)

        # jpg colors don't match the display very well, png colors match
        # better
        pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, 0, 8, width, height)
        pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(), 0, 0, 0, 0, width, height)

        # set the default quality, if we are writing a JPEG.
        # http://www.pygtk.org/docs/pygtk/class-gdkpixbuf.html#method-gdkpixbuf--save
        options = restrict_dict(kwargs, ["quality"])
        if format in ["jpg", "jpeg"]:
            if "quality" not in options:
                options["quality"] = rcParams["savefig.jpeg_quality"]
            options["quality"] = str(options["quality"])

        pixbuf.save(filename, format, options=options)
开发者ID:giapdangle,项目名称:matplotlib,代码行数:19,代码来源:backend_gdk.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python cbook.safe_masked_invalid函数代码示例发布时间:2022-05-27
下一篇:
Python cbook.open_file_cm函数代码示例发布时间: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