跳转到主要内容

用于暴露matplotlib图形的渲染器

项目描述

关于tgext.matplotrender

https://travis-ci.org/amol-/tgext.matplotrender.png https://coveralls.io/repos/amol-/tgext.matplotrender/badge.png https://img.shields.io/:license-mit-blue.svg?style=flat-square

tgext.matplotrender是TurboGears2的一个扩展,它提供了一个Matplotlib图形的渲染引擎。

安装

tgext.matplotrender可以从pypi安装

pip install tgext.matplotrender

应该对大多数用户来说都能正常工作。

启用

要启用tgext.matplotrender,请将matplotfig渲染器添加到您的配置中

base_config.renderers.append('matplotfig')

并在您的config/app_cfg.py中连接渲染引擎

import tgext.matplotrender
tgext.matplotrender.plugme(base_config)

使用方法

使用tgext.matplotrender就像暴露一个带有matplotfig模板的操作,并在操作返回字典的fig键中返回图形本身一样简单。

给定以下图形

def _make_fig():
    fig = matplotlib.figure.Figure(figsize=(9, 6))
    fig.Name = "Sinewave"
    ax = fig.add_subplot(111)
    ax.set_xlabel("angle")
    ax.set_ylabel("amplitude")
    t = numpy.arange(0.0, 2.0, 0.01)
    s1 = numpy.sin(2 * numpy.pi * t)
    ax.plot(t, s1, color="k")
    return fig

可以通过TurboGears操作进行暴露,如下所示

class RootController(TGController):
    @expose('matplotfig')
    def figure(self, *args, **kwargs):
        return dict(fig=_make_fig())

    @expose('matplotfig', render_params=dict(dpi=36))
    def lowres(self, *args, **kwargs):
        return dict(fig=_make_fig())

    @expose('matplotfig')
    def customres(self, *args, **kwargs):
        options = {}
        try:
            options['dpi'] = int(kwargs['dpi'])
        except:
            pass
        return dict(fig=_make_fig(), **options)

字典中提供的任何其他值都将作为matplotlib的print_figure参数使用

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

tgext.matplotrender-0.0.1.tar.gz (3.3 kB 查看哈希值)

上传时间: