It's working, thanks for the patience Diez

here is the code:

class RootController(BaseController):
    error = ErrorController()

    @expose('mplibtest.templates.index')
    def index(self):
        """Handle the front-page."""
        return dict(page='index')

    @expose('mplibtest.templates.about')
    def about(self):
        """Handle the 'about' page."""
        return dict(page='about')

    def expose_matplot_figure(f=None, **render_opts):

        def get_fig(result):
            if isinstance(result, dict):
                fig = result['fig']
                del result['fig']
                return fig
            else:
                return result

        def get_render_opts(result):
            if isinstance(result, dict):
                render_opts.update(result)
            return render_opts

        def wrap_f_with_render_figure(f):
            def render_figure(*pargs, **vargs):
                # Make the PNG
                result = f(*pargs, **vargs)
                canvas = FigureCanvasAgg(get_fig(result))
                rendered_fig = StringIO.StringIO()
                canvas.print_figure(rendered_fig, **get_render_opts
(result))
                return rendered_fig.getvalue()
            return expose(content_type="image/png")(render_figure)

        if f is None:
            # This corresponds to the usage @expose_matplotlib_figure
(dpi=20)
            return wrap_f_with_render_figure
        else:
            # This corresponds to the usage @expose_matplotlib_figure
            return wrap_f_with_render_figure(f)

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

    @expose_matplot_figure
    def sinegraph_default_dpi(self):
        return self.sample_fig()


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to