• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mathtext.MathTextParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中matplotlib.mathtext.MathTextParser的典型用法代码示例。如果您正苦于以下问题:Python MathTextParser类的具体用法?Python MathTextParser怎么用?Python MathTextParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了MathTextParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:nilqed,项目名称:IPyXt,代码行数:28,代码来源:sympyprt3.py


示例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
开发者ID:asmeurer,项目名称:IPyXt,代码行数:57,代码来源:ipy_tex.py


示例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')
开发者ID:AndreI11,项目名称:SatStressGui,代码行数:25,代码来源:backend_agg.py


示例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")
开发者ID:,项目名称:,代码行数:25,代码来源:


示例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')
开发者ID:astraw,项目名称:matplotlib,代码行数:7,代码来源:backend_macosx.py


示例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()
开发者ID:4over7,项目名称:matplotlib,代码行数:34,代码来源:backend_svg.py


示例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)
开发者ID:tomflannaghan,项目名称:matplotlib,代码行数:7,代码来源:backend_cairo.py


示例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")
开发者ID:zoccolan,项目名称:eyetracker,代码行数:34,代码来源:backend_ps.py


示例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")
开发者ID:08s011003,项目名称:nupic,代码行数:8,代码来源:backend_gdk.py


示例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')
开发者ID:08s011003,项目名称:nupic,代码行数:8,代码来源:backend_cairo.py


示例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()
开发者ID:nilqed,项目名称:IPyXt,代码行数:9,代码来源:sympyprt3.py


示例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()
开发者ID:Gwillink,项目名称:sympy_ipython_notebooks,代码行数:9,代码来源:sympyprt.py


示例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
开发者ID:jarrodmillman,项目名称:ipython,代码行数:44,代码来源:latextools.py


示例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 = []
开发者ID:kivy-garden,项目名称:garden.matplotlib,代码行数:10,代码来源:backend_kivy.py


示例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
开发者ID:adnanb59,项目名称:matplotlib,代码行数:10,代码来源:textpath.py


示例16: __init__

    def __init__(self, dpi):
        """
        """
        if _debug: print('%s.%s()' % (self.__class__.__name__, _fn_name()))
        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)
开发者ID:NigelKB,项目名称:matplotlib,代码行数:11,代码来源:backend_cairo.py


示例17: __init__

 def __init__(self, dpi):
     self.dpi = dpi
     self.width = 640.0 * dpi / 80
     self.height = 480.0 * dpi / 80
     mwidth, mheight, width, height = gr.inqdspsize()
     if (width / (mwidth / 0.0256) < 200):
         mwidth *= self.width / width
         gr.setwsviewport(0, mwidth, 0, mwidth * 0.75)
     else:
         gr.setwsviewport(0, 0.192, 0, 0.144)
     gr.setwswindow(0, 1, 0, 0.75)
     gr.setviewport(0, 1, 0, 0.75)
     gr.setwindow(0, self.width, 0, self.height)
     self.mathtext_parser = MathTextParser('agg')
     self.texmanager = TexManager()
开发者ID:albertocabello,项目名称:gr,代码行数:15,代码来源:backend_gr.py


示例18: __init__

    def __init__(self, width, height, svgwriter, basename=None):
        self.width=width
        self.height=height
        self._svgwriter = svgwriter
        if rcParams['path.simplify']:
            self.simplify = (width, height)
        else:
            self.simplify = None

        self._groupd = {}
        if not rcParams['svg.image_inline']:
            assert basename is not None
            self.basename = basename
            self._imaged = {}
        self._clipd = {}
        self._char_defs = {}
        self._markers = {}
        self._path_collection_id = 0
        self._imaged = {}
        self.mathtext_parser = MathTextParser('SVG')
        svgwriter.write(svgProlog%(width,height,width,height))
开发者ID:08s011003,项目名称:nupic,代码行数:21,代码来源:backend_svg.py


示例19: __init__

    def __init__(self, width, height, dpi):
        if __debug__:
            verbose.report("RendererAgg.__init__", "debug-annoying")
        RendererBase.__init__(self)

        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)
        self._filter_renderers = []

        if __debug__:
            verbose.report("RendererAgg.__init__ _RendererAgg done", "debug-annoying")

        self._update_methods()
        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")
开发者ID:Kojoley,项目名称:matplotlib,代码行数:22,代码来源:backend_agg.py


示例20: RendererAgg

class RendererAgg(RendererBase):
    """
    The renderer handles all the drawing primitives using a graphics
    context instance that controls the colors/styles
    """
    debug=1

    # we want to cache the fonts at the class level so that when
    # multiple figures are created we can reuse them.  This helps with
    # a bug on windows where the creation of too many figures leads to
    # too many open file handles.  However, storing them at the class
    # level is not thread safe.  The solution here is to let the
    # FigureCanvas acquire a lock on the fontd at the start of the
    # draw, and release it when it is done.  This allows multiple
    # renderers to share the cached fonts, but only one figure can
    # draw at at time and so the font cache is used by only one
    # renderer at a time

    lock = threading.RLock()
    _fontd = maxdict(50)
    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.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)
        self._filter_renderers = []

        if __debug__: verbose.report('RendererAgg.__init__ _RendererAgg done',
                                     'debug-annoying')

        self._update_methods()
        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')

    def __getstate__(self):
        # We only want to preserve the init keywords of the Renderer.
        # Anything else can be re-created.
        return {'width': self.width, 'height': self.height, 'dpi': self.dpi}

    def __setstate__(self, state):
        self.__init__(state['width'], state['height'], state['dpi'])

    def _get_hinting_flag(self):
        if rcParams['text.hinting']:
            return LOAD_FORCE_AUTOHINT
        else:
            return LOAD_NO_HINTING

    # for filtering to work with rasterization, methods needs to be wrapped.
    # maybe there is better way to do it.
    def draw_markers(self, *kl, **kw):
        return self._renderer.draw_markers(*kl, **kw)

    def draw_path_collection(self, *kl, **kw):
        return self._renderer.draw_path_collection(*kl, **kw)

    def _update_methods(self):
        self.draw_quad_mesh = self._renderer.draw_quad_mesh
        self.draw_gouraud_triangle = self._renderer.draw_gouraud_triangle
        self.draw_gouraud_triangles = self._renderer.draw_gouraud_triangles
        self.draw_image = self._renderer.draw_image
        self.copy_from_bbox = self._renderer.copy_from_bbox
        self.get_content_extents = self._renderer.get_content_extents

    def tostring_rgba_minimized(self):
        extents = self.get_content_extents()
        bbox = [[extents[0], self.height - (extents[1] + extents[3])],
                [extents[0] + extents[2], self.height - extents[1]]]
        region = self.copy_from_bbox(bbox)
        return np.array(region), extents

    def draw_path(self, gc, path, transform, rgbFace=None):
        """
        Draw the path
        """
        nmax = rcParams['agg.path.chunksize'] # here at least for testing
        npts = path.vertices.shape[0]
        if (nmax > 100 and npts > nmax and path.should_simplify and
                rgbFace is None and gc.get_hatch() is None):
            nch = np.ceil(npts/float(nmax))
            chsize = int(np.ceil(npts/nch))
            i0 = np.arange(0, npts, chsize)
            i1 = np.zeros_like(i0)
            i1[:-1] = i0[1:] - 1
            i1[-1] = npts
            for ii0, ii1 in zip(i0, i1):
                v = path.vertices[ii0:ii1,:]
                c = path.codes
                if c is not None:
                    c = c[ii0:ii1]
                    c[0] = Path.MOVETO # move to end of last chunk
                p = Path(v, c)
#.........这里部分代码省略.........
开发者ID:7924102,项目名称:matplotlib,代码行数:101,代码来源:backend_agg.py



注:本文中的matplotlib.mathtext.MathTextParser类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mlab.bivariate_normal函数代码示例发布时间:2022-05-27
下一篇:
Python markers.MarkerStyle类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap