Skip to main content

Renderer to expose matplotlib figures

Project description

About tgext.matplotrender

tgext.matplotrender is a TurboGears2 extension that provides a Rendering Engine for MatplotLib Figures.


tgext.matplotrender can be installed from pypi:

pip install tgext.matplotrender

should just work for most of the users.


To enable tgext.matplotrender add the matplotfig renderer to your configuration:


and plug the rendering engine inside your config/

import tgext.matplotrender


Using tgext.matplotrender is as simple as exposing an action with the matplotfig template and returning the figure itself inside the fig key of action returned dictionary.

Given the following figure:

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

It can be exposed through TurboGears actions as:

class RootController(TGController):
    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())

    def customres(self, *args, **kwargs):
        options = {}
            options['dpi'] = int(kwargs['dpi'])
        return dict(fig=_make_fig(), **options)

Any other value provided in the dictionary will be used as a print_figure argument in matplotlib

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for tgext.matplotrender, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size tgext.matplotrender-0.0.1.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page