本文整理汇总了Python中matplotlib.mathtext.MathTextParser.to_png方法的典型用法代码示例。如果您正苦于以下问题:Python MathTextParser.to_png方法的具体用法?Python MathTextParser.to_png怎么用?Python MathTextParser.to_png使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.mathtext.MathTextParser
的用法示例。
在下文中一共展示了MathTextParser.to_png方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TeX1
# 需要导入模块: from matplotlib.mathtext import MathTextParser [as 别名]
# 或者: from matplotlib.mathtext.MathTextParser import to_png [as 别名]
class TeX1():
"""
Render TeX code with matplotlib mathtext. Doesn't need a LaTeX installation.
@enocde ........ Enocde base64
@init_render ... Render the PNG image when creating an instance.
"""
def __init__(self, src, encode = False, cfg = fs()):
self.cfg = copy(cfg)
self.src = src
self.encode = encode
self.png = None
if self.cfg.initrender:
self.render(self.cfg)
def render(self, cfg):
self.mtp = MathTextParser('bitmap')
f = StringIO()
self.mtp.to_png(f, self.src, cfg.forecolor, cfg.resolution, cfg.fontsize)
bin_data = f.getvalue()
if self.encode:
bin_data = encodestring(bin_data)
self.png = bin_data
f.close()
def _repr_png_(self):
return self.png
示例2: TeX1
# 需要导入模块: from matplotlib.mathtext import MathTextParser [as 别名]
# 或者: from matplotlib.mathtext.MathTextParser import to_png [as 别名]
class TeX1():
"""
Render TeX code with matplotlib mathtext. Doesn't need a LaTeX installation.
@texstr ........ TeX code as string
@color ......... Font color
@dpi ........... Resolution (dots per inch)
@fontsize ...... Font size
@enocde ........ Enocde base64
@init_render ... Render the PNG image when creating an instance.
If 'False' one has to call the render method explicitly.
"""
def __init__(self, texstr, color = 'black', dpi = 120, fontsize = 12,
encode=False, init_render = True):
self.texstr = texstr
self.color = color
self.dpi = dpi
self.fontsize = fontsize
self.encode = encode
self.init_render = init_render
self.png = None
if self.init_render:
self.render()
def render(self):
self.mtp = MathTextParser('bitmap')
f = StringIO()
self.mtp.to_png(f, self.texstr, self.color, self.dpi, self.fontsize)
bin_data = f.getvalue()
if self.encode:
bin_data = encodestring(bin_data)
self.png = bin_data
f.close()
def set_texstr(self, texstr):
self.texstr = texstr
self.render()
def set_color(self, color):
self.color = color
self.render()
def set_dpi(self, dpi):
self.dpi = dpi
self.render()
def set_fontsize(self, fontsize):
self.fontsize = fontsize
self.render()
def set_encode(self, encode):
self.encode = encode
self.render()
def _repr_png_(self):
return self.png