本文整理汇总了Python中matplotlib.font_manager.findfont方法的典型用法代码示例。如果您正苦于以下问题:Python font_manager.findfont方法的具体用法?Python font_manager.findfont怎么用?Python font_manager.findfont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.font_manager
的用法示例。
在下文中一共展示了font_manager.findfont方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_font_afm
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import findfont [as 别名]
def _get_font_afm(self, prop):
key = hash(prop)
font = self.afm_font_cache.get(key)
if font is None:
filename = findfont(
prop, fontext='afm', directory=self.file._core14fontdir)
if filename is None:
filename = findfont(
"Helvetica", fontext='afm',
directory=self.file._core14fontdir)
font = self.afm_font_cache.get(filename)
if font is None:
with open(filename, 'rb') as fh:
font = AFM(fh)
self.afm_font_cache[filename] = font
self.afm_font_cache[key] = font
return font
示例2: _get_agg_font
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import findfont [as 别名]
def _get_agg_font(self, prop):
"""
Get the font for text instance t, cacheing for efficiency
"""
if __debug__: verbose.report('RendererAgg._get_agg_font',
'debug-annoying')
key = hash(prop)
font = RendererAgg._fontd.get(key)
if font is None:
fname = findfont(prop)
font = RendererAgg._fontd.get(fname)
if font is None:
font = FT2Font(
str(fname),
hinting_factor=rcParams['text.hinting_factor'])
RendererAgg._fontd[fname] = font
RendererAgg._fontd[key] = font
font.clear()
size = prop.get_size_in_points()
font.set_size(size, self.dpi)
return font
示例3: render_glyph
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import findfont [as 别名]
def render_glyph(self, ox, oy, info):
oy = self.height - oy + info.offset
postscript_name = info.postscript_name
fontsize = info.fontsize
symbol_name = info.symbol_name
if (postscript_name, fontsize) != self.lastfont:
ps = """/%(postscript_name)s findfont
%(fontsize)s scalefont
setfont
""" % locals()
self.lastfont = postscript_name, fontsize
self.pswriter.write(ps)
ps = """%(ox)f %(oy)f moveto
/%(symbol_name)s glyphshow\n
""" % locals()
self.pswriter.write(ps)
示例4: __init__
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import findfont [as 别名]
def __init__(self, default_font_prop):
Fonts.__init__(self, default_font_prop, MathtextBackendPs())
self.glyphd = {}
self.fonts = {}
filename = findfont(default_font_prop, fontext='afm',
directory=self.basepath)
if filename is None:
filename = findfont('Helvetica', fontext='afm',
directory=self.basepath)
with open(filename, 'r') as fd:
default_font = AFM(fd)
default_font.fname = filename
self.fonts['default'] = default_font
self.fonts['regular'] = default_font
self.pswriter = StringIO()
示例5: get_fontspec
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import findfont [as 别名]
def get_fontspec():
"""Build fontspec preamble from rc."""
latex_fontspec = []
texcommand = rcParams["pgf.texsystem"]
if texcommand != "pdflatex":
latex_fontspec.append("\\usepackage{fontspec}")
if texcommand != "pdflatex" and rcParams["pgf.rcfonts"]:
families = ["serif", "sans\\-serif", "monospace"]
commands = ["setmainfont", "setsansfont", "setmonofont"]
for family, command in zip(families, commands):
# 1) Forward slashes also work on Windows, so don't mess with
# backslashes. 2) The dirname needs to include a separator.
path = pathlib.Path(fm.findfont(family))
latex_fontspec.append(r"\%s{%s}[Path=%s]" % (
command, path.name, path.parent.as_posix() + "/"))
return "\n".join(latex_fontspec)
示例6: _get_agg_font
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import findfont [as 别名]
def _get_agg_font(self, prop):
"""
Get the font for text instance t, cacheing for efficiency
"""
if __debug__: verbose.report('RendererAgg._get_agg_font',
'debug-annoying')
key = hash(prop)
font = RendererAgg._fontd.get(key)
if font is None:
fname = findfont(prop)
font = RendererAgg._fontd.get(fname)
if font is None:
font = FT2Font(
fname,
hinting_factor=rcParams['text.hinting_factor'])
RendererAgg._fontd[fname] = font
RendererAgg._fontd[key] = font
font.clear()
size = prop.get_size_in_points()
font.set_size(size, self.dpi)
return font
示例7: __init__
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import findfont [as 别名]
def __init__(self, default_font_prop):
Fonts.__init__(self, default_font_prop, MathtextBackendPs())
self.glyphd = {}
self.fonts = {}
filename = findfont(default_font_prop, fontext='afm',
directory=self.basepath)
if filename is None:
filename = findfont('Helvetica', fontext='afm',
directory=self.basepath)
with open(filename, 'r') as fd:
default_font = AFM(fd)
default_font.fname = filename
self.fonts['default'] = default_font
self.fonts['regular'] = default_font
self.pswriter = six.moves.cStringIO()
示例8: __init__
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import findfont [as 别名]
def __init__(self, *args, **kwargs):
# This must come first so the backend's owner is set correctly
if isinstance(self, DejaVuSerifFonts):
self.cm_fallback = StixFonts(*args, **kwargs)
else:
self.cm_fallback = StixSansFonts(*args, **kwargs)
self.bakoma = BakomaFonts(*args, **kwargs)
TruetypeFonts.__init__(self, *args, **kwargs)
self.fontmap = {}
# Include Stix sized alternatives for glyphs
self._fontmap.update({
1 : 'STIXSizeOneSym',
2 : 'STIXSizeTwoSym',
3 : 'STIXSizeThreeSym',
4 : 'STIXSizeFourSym',
5 : 'STIXSizeFiveSym'})
for key, name in self._fontmap.items():
fullpath = findfont(name)
self.fontmap[key] = fullpath
self.fontmap[name] = fullpath
示例9: fontName
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import findfont [as 别名]
def fontName(self, fontprop):
"""
Select a font based on fontprop and return a name suitable for
Op.selectfont. If fontprop is a string, it will be interpreted
as the filename (or dvi name) of the font.
"""
if is_string_like(fontprop):
filename = fontprop
elif rcParams['pdf.use14corefonts']:
filename = findfont(
fontprop, fontext='afm', directory=self._core14fontdir)
if filename is None:
filename = findfont(
"Helvetica", fontext='afm', directory=self._core14fontdir)
else:
filename = findfont(fontprop)
Fx = self.fontNames.get(filename)
if Fx is None:
Fx = Name('F%d' % self.nextFont)
self.fontNames[filename] = Fx
self.nextFont += 1
matplotlib.verbose.report(
'Assigning font %s = %s' % (Fx, filename),
'debug')
return Fx
示例10: _get_font_ttf
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import findfont [as 别名]
def _get_font_ttf(self, prop):
key = hash(prop)
font = self.truetype_font_cache.get(key)
if font is None:
filename = findfont(prop)
font = self.truetype_font_cache.get(filename)
if font is None:
font = FT2Font(str(filename))
self.truetype_font_cache[filename] = font
self.truetype_font_cache[key] = font
font.clear()
font.set_size(prop.get_size_in_points(), 72)
return font
示例11: set_font
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import findfont [as 别名]
def set_font(self, fontname, fontsize, store=1):
if rcParams['ps.useafm']: return
if (fontname,fontsize) != (self.fontname,self.fontsize):
out = ("/%s findfont\n"
"%1.3f scalefont\n"
"setfont\n" % (fontname, fontsize))
self._pswriter.write(out)
if store: self.fontname = fontname
if store: self.fontsize = fontsize
示例12: _get_font_afm
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import findfont [as 别名]
def _get_font_afm(self, prop):
key = hash(prop)
font = self.afmfontd.get(key)
if font is None:
fname = findfont(prop, fontext='afm', directory=self._afm_font_dir)
if fname is None:
fname = findfont(
"Helvetica", fontext='afm', directory=self._afm_font_dir)
font = self.afmfontd.get(fname)
if font is None:
with open(fname, 'rb') as fh:
font = AFM(fh)
self.afmfontd[fname] = font
self.afmfontd[key] = font
return font
示例13: _get_font
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import findfont [as 别名]
def _get_font(self, prop):
key = hash(prop)
font = self.fontd.get(key)
if font is None:
fname = findfont(prop)
font = self.fontd.get(fname)
if font is None:
font = FT2Font(str(fname))
self.fontd[fname] = font
self.fontd[key] = font
font.clear()
size = prop.get_size_in_points()
font.set_size(size, 72.0)
return font