显示matplotlib图形的渲染器
tgext.matplotrender的Python项目详细描述
安装
tgext.matplotrender可以从pypi安装:
pip install tgext.matplotrender
应该只对大多数用户有效。
启用
若要启用tgext.matplotrender,请将matplotfig渲染器添加到 配置:
base_config.renderers.append('matplotfig')
并将渲染引擎插入到config/app_cfg.py:
importtgext.matplotrendertgext.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")returnfig
它可以通过涡轮齿轮的作用暴露如下:
classRootController(TGController):@expose('matplotfig')deffigure(self,*args,**kwargs):returndict(fig=_make_fig())@expose('matplotfig',render_params=dict(dpi=36))deflowres(self,*args,**kwargs):returndict(fig=_make_fig())@expose('matplotfig')defcustomres(self,*args,**kwargs):options={}try:options['dpi']=int(kwargs['dpi'])except:passreturndict(fig=_make_fig(),**options)
字典中提供的任何其他值将用作 matplotlib
中的print_figure参数