本文整理汇总了Python中matplotlib.mathtext.MathTextParser类的典型用法代码示例。如果您正苦于以下问题:Python MathTextParser类的具体用法?Python MathTextParser怎么用?Python MathTextParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MathTextParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TeX1
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
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
示例3: __init__
def __init__(self, width, height, dpi):
if __debug__: verbose.report('RendererAgg.__init__', 'debug-annoying')
RendererBase.__init__(self)
self.texd = maxdict(50) # a cache of tex image rasters
self._fontd = maxdict(50)
self.dpi = dpi
self.width = width
self.height = height
if __debug__: verbose.report('RendererAgg.__init__ width=%s, height=%s'%(width, height), 'debug-annoying')
self._renderer = _RendererAgg(int(width), int(height), dpi, debug=False)
if __debug__: verbose.report('RendererAgg.__init__ _RendererAgg done',
'debug-annoying')
#self.draw_path = self._renderer.draw_path # see below
self.draw_markers = self._renderer.draw_markers
self.draw_path_collection = self._renderer.draw_path_collection
self.draw_quad_mesh = self._renderer.draw_quad_mesh
self.draw_image = self._renderer.draw_image
self.copy_from_bbox = self._renderer.copy_from_bbox
self.tostring_rgba_minimized = self._renderer.tostring_rgba_minimized
self.mathtext_parser = MathTextParser('Agg')
self.bbox = Bbox.from_bounds(0, 0, self.width, self.height)
if __debug__: verbose.report('RendererAgg.__init__ done',
'debug-annoying')
示例4: __init__
def __init__(self, width, height, pswriter, dpi=72):
RendererBase.__init__(self)
self.width = width
self.height = height
self._pswriter = pswriter
if rcParams['text.usetex']:
self.textcnt = 0
self.psfrag = []
self.dpi = dpi
# current renderer state (None=uninitialised)
self.color = None
self.linewidth = None
self.linejoin = None
self.linecap = None
self.linedash = None
self.fontname = None
self.fontsize = None
self.hatch = None
self.image_magnification = dpi/72.0
self._clip_paths = {}
self._path_collection_id = 0
self.used_characters = {}
self.mathtext_parser = MathTextParser("PS")
示例5: __init__
def __init__(self, dpi, width, height):
RendererBase.__init__(self)
self.dpi = dpi
self.width = width
self.height = height
self.gc = GraphicsContextMac()
self.mathtext_parser = MathTextParser('MacOSX')
示例6: __init__
def __init__(self, width, height, svgwriter, basename=None, image_dpi=72):
self.width = width
self.height = height
self.writer = XMLWriter(svgwriter)
self.image_dpi = image_dpi # the actual dpi we want to rasterize stuff with
self._groupd = {}
if not rcParams['svg.image_inline']:
assert basename is not None
self.basename = basename
self._imaged = {}
self._clipd = OrderedDict()
self._char_defs = {}
self._markers = {}
self._path_collection_id = 0
self._imaged = {}
self._hatchd = OrderedDict()
self._has_gouraud = False
self._n_gradients = 0
self._fonts = OrderedDict()
self.mathtext_parser = MathTextParser('SVG')
RendererBase.__init__(self)
self._glyph_map = dict()
svgwriter.write(svgProlog)
self._start_id = self.writer.start(
'svg',
width='%ipt' % width, height='%ipt' % height,
viewBox='0 0 %i %i' % (width, height),
xmlns="http://www.w3.org/2000/svg",
version="1.1",
attrib={'xmlns:xlink': "http://www.w3.org/1999/xlink"})
self._write_default_style()
示例7: __init__
def __init__(self, dpi):
self.dpi = dpi
self.gc = GraphicsContextCairo(renderer=self)
self.text_ctx = cairo.Context(
cairo.ImageSurface(cairo.FORMAT_ARGB32, 1, 1))
self.mathtext_parser = MathTextParser('Cairo')
RendererBase.__init__(self)
示例8: __init__
def __init__(self, width, height, pswriter, imagedpi=72):
"""
Although postscript itself is dpi independent, we need to
imform the image code about a requested dpi to generate high
res images and them scale them before embeddin them
"""
RendererBase.__init__(self)
self.width = width
self.height = height
self._pswriter = pswriter
if rcParams['text.usetex']:
self.textcnt = 0
self.psfrag = []
self.imagedpi = imagedpi
if rcParams['path.simplify']:
self.simplify = (width * imagedpi, height * imagedpi)
else:
self.simplify = None
# current renderer state (None=uninitialised)
self.color = None
self.linewidth = None
self.linejoin = None
self.linecap = None
self.linedash = None
self.fontname = None
self.fontsize = None
self._hatches = {}
self.image_magnification = imagedpi/72.0
self._clip_paths = {}
self._path_collection_id = 0
self.used_characters = {}
self.mathtext_parser = MathTextParser("PS")
示例9: __init__
def __init__(self, gtkDA, dpi):
# widget gtkDA is used for:
# '<widget>.create_pango_layout(s)'
# cmap line below)
self.gtkDA = gtkDA
self.dpi = dpi
self._cmap = gtkDA.get_colormap()
self.mathtext_parser = MathTextParser("Agg")
示例10: __init__
def __init__(self, dpi):
"""
"""
if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
self.dpi = dpi
self.text_ctx = cairo.Context (
cairo.ImageSurface (cairo.FORMAT_ARGB32,1,1))
self.mathtext_parser = MathTextParser('Cairo')
示例11: render
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()
示例12: 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()
示例13: math_to_image
def math_to_image(s, filename_or_obj, prop=None, dpi=None, format=None):
"""
Given a math expression, renders it in a closely-clipped bounding
box to an image file.
*s*
A math expression. The math portion should be enclosed in
dollar signs.
*filename_or_obj*
A filepath or writable file-like object to write the image data
to.
*prop*
If provided, a FontProperties() object describing the size and
style of the text.
*dpi*
Override the output dpi, otherwise use the default associated
with the output format.
*format*
The output format, eg. 'svg', 'pdf', 'ps' or 'png'. If not
provided, will be deduced from the filename.
"""
from matplotlib import figure
# backend_agg supports all of the core output formats
from matplotlib.backends import backend_agg
from matplotlib.font_manager import FontProperties
from matplotlib.mathtext import MathTextParser
if prop is None:
prop = FontProperties()
parser = MathTextParser("path")
width, height, depth, _, _ = parser.parse(s, dpi=72, prop=prop)
fig = figure.Figure(figsize=(width / 72.0, height / 72.0))
fig.text(0, depth / height, s, fontproperties=prop)
backend_agg.FigureCanvasAgg(fig)
fig.savefig(filename_or_obj, dpi=dpi, format=format)
return depth
示例14: __init__
def __init__(self, widget):
super(RendererKivy, self).__init__()
self.widget = widget
self.dpi = widget.figure.dpi
self._markers = {}
# Can be enhanced by using TextToPath matplotlib, textpath.py
self.mathtext_parser = MathTextParser("Bitmap")
self.list_goraud_triangles = []
self.clip_rectangles = []
self.labels_inside_plot = []
示例15: __init__
def __init__(self):
self.mathtext_parser = MathTextParser('path')
self.tex_font_map = None
from matplotlib.cbook import maxdict
self._ps_fontd = maxdict(50)
self._texmanager = None
self._adobe_standard_encoding = None