本文整理汇总了Python中matplotlib.font_manager.FontProperties方法的典型用法代码示例。如果您正苦于以下问题:Python font_manager.FontProperties方法的具体用法?Python font_manager.FontProperties怎么用?Python font_manager.FontProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.font_manager
的用法示例。
在下文中一共展示了font_manager.FontProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_bar
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def draw_bar(data, labels, width=None, xticks_font_fname=None, legend_kwargs=dict()):
n = len(labels)
m = len(data)
if not width:
width = 1. / (m + .6)
off = 1.
legend_bar = []
legend_text = []
for i, a in enumerate(data):
for j, b in enumerate(a):
assert n == len(b['data'])
ind = [off + k + (i + (1 - m) / 2) * width for k in range(n)]
bottom = [sum(d) for d in zip(*[c['data'] for c in a[j + 1:]])] or None
p = plt.bar(ind, b['data'], width, bottom=bottom, color=b.get('color'))
legend_bar.append(p[0])
legend_text.append(b['legend'])
ind = [off + i for i, label in enumerate(labels) if label is not None]
labels = [label for label in labels if label is not None]
font = FontProperties(fname=xticks_font_fname)
plt.xticks(ind, labels, fontproperties=font, ha='center')
plt.legend(legend_bar, legend_text, **legend_kwargs)
示例2: _get_text1
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def _get_text1(self):
'Get the default Text instance'
# the y loc is 3 points below the min of y axis
# get the affine as an a,b,c,d,tx,ty list
# x in data coords, y in axes coords
#t = mtext.Text(
trans, vert, horiz = self._get_text1_transform()
t = mtext.Text(
x=0, y=0,
fontproperties=font_manager.FontProperties(size=self._labelsize),
color=self._labelcolor,
verticalalignment=vert,
horizontalalignment=horiz,
)
t.set_transform(trans)
self._set_artist_props(t)
return t
示例3: _get_text2
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def _get_text2(self):
'Get the default Text 2 instance'
# x in data coords, y in axes coords
#t = mtext.Text(
trans, vert, horiz = self._get_text2_transform()
t = mtext.Text(
x=0, y=1,
fontproperties=font_manager.FontProperties(size=self._labelsize),
color=self._labelcolor,
verticalalignment=vert,
horizontalalignment=horiz,
)
t.set_transform(trans)
self._set_artist_props(t)
return t
示例4: _get_label
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def _get_label(self):
# x in axes coords, y in display coords (to be updated at draw
# time by _update_label_positions)
label = mtext.Text(x=0.5, y=0,
fontproperties=font_manager.FontProperties(
size=rcParams['axes.labelsize'],
weight=rcParams['axes.labelweight']),
color=rcParams['axes.labelcolor'],
verticalalignment='top',
horizontalalignment='center',
)
label.set_transform(mtransforms.blended_transform_factory(
self.axes.transAxes, mtransforms.IdentityTransform()))
self._set_artist_props(label)
self.label_position = 'bottom'
return label
示例5: set_title
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def set_title(self, title, prop=None):
"""
set the legend title. Fontproperties can be optionally set
with *prop* parameter.
"""
self._legend_title_box._text.set_text(title)
if prop is not None:
if isinstance(prop, dict):
prop = FontProperties(**prop)
self._legend_title_box._text.set_fontproperties(prop)
if title:
self._legend_title_box.set_visible(True)
else:
self._legend_title_box.set_visible(False)
示例6: get_depth
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def get_depth(self, texstr, dpi=120, fontsize=14):
"""
Returns the offset of the baseline from the bottom of the
image in pixels.
*texstr*
A valid mathtext string, eg r'IQ: $\sigma_i=15$'
*dpi*
The dots-per-inch to render the text
*fontsize*
The font size in points
"""
assert(self._output=="bitmap")
prop = FontProperties(size=fontsize)
ftimage, depth = self.parse(texstr, dpi=dpi, prop=prop)
return depth
示例7: _get_text1
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def _get_text1(self):
'Get the default Text instance'
# the y loc is 3 points below the min of y axis
# get the affine as an a,b,c,d,tx,ty list
# x in data coords, y in axes coords
trans, vert, horiz = self._get_text1_transform()
t = mtext.Text(
x=0, y=0,
fontproperties=font_manager.FontProperties(size=self._labelsize),
color=self._labelcolor,
verticalalignment=vert,
horizontalalignment=horiz,
)
t.set_transform(trans)
self._set_artist_props(t)
return t
示例8: _get_label
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def _get_label(self):
# x in axes coords, y in display coords (to be updated at draw
# time by _update_label_positions)
label = mtext.Text(x=0.5, y=0,
fontproperties=font_manager.FontProperties(
size=rcParams['axes.labelsize'],
weight=rcParams['axes.labelweight']),
color=rcParams['axes.labelcolor'],
verticalalignment='top',
horizontalalignment='center')
label.set_transform(mtransforms.blended_transform_factory(
self.axes.transAxes, mtransforms.IdentityTransform()))
self._set_artist_props(label)
self.label_position = 'bottom'
return label
示例9: set_title
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def set_title(self, title, prop=None):
"""
Set the legend title. Fontproperties can be optionally set
with *prop* parameter.
"""
self._legend_title_box._text.set_text(title)
if title:
self._legend_title_box._text.set_visible(True)
self._legend_title_box.set_visible(True)
else:
self._legend_title_box._text.set_visible(False)
self._legend_title_box.set_visible(False)
if prop is not None:
if isinstance(prop, dict):
prop = FontProperties(**prop)
self._legend_title_box._text.set_fontproperties(prop)
self.stale = True
示例10: font_properties_from_style
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def font_properties_from_style(style: dict) -> FontProperties:
""" convert a style to a FontProperties object """
fp = FontProperties()
for key, value in style.items():
if key == "font-family":
fp.set_family(value)
if key == "font-size":
fp.set_size(svgUnitToMpl(value))
if key == "font-weight":
fp.set_weight(value)
if key == "font-style":
fp.set_style(value)
if key == "font-variant":
fp.set_variant(value)
if key == "font-stretch":
fp.set_stretch(value)
return fp
示例11: GetFontProperties
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def GetFontProperties(font):
fontfile = r"C:\WINDOWS\Fonts\{0}".format(font['family'])
if not os.path.exists(fontfile):
fp = FontProperties(family=font['family'], weight=font['weight'], size=font['size'])
else:
fp = FontProperties(fname=fontfile, weight=font['weight'], size=font['size'])
return fp
示例12: DrawTitle
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def DrawTitle(m, title, headtxt):
if m is plt:
if title.mtitleposition is None:
for desc in title.descs:
fontfile = r"C:\WINDOWS\Fonts\{0}".format(desc.font['family'])
if not os.path.exists(fontfile):
font = FontProperties(size=desc.font['fontsize'], weight=desc.font['weight'])
else:
font = FontProperties(fname=fontfile, size=desc.font['fontsize'], weight=desc.font['weight'])
plt.text(desc.pos[0], desc.pos[1], desc.text,
# size=desc.font['fontsize'], weight=desc.font['weight'],
color=desc.font['color'],
fontdict=desc.font,
fontproperties=font,
rotation=0,
ha='left', va='top')
else:
if title.mtitleposition == [0, 0]:
plt.title(headtxt, fontdict={'fontsize': 14})
else:
plt.text(title.mtitleposition[0], title.mtitleposition[1], headtxt,
size=14,
weight='bold',
# color='blue',
# fontdict=desc.font,
# fontproperties=font,
rotation=0,
ha='left', va='top')
else:
plt.title(headtxt)
示例13: plot_disp
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def plot_disp(ax, tws, top_plot, font_size):
S = [p.s for p in tws]#map(lambda p:p.s, tws)
d_Ftop = []
Fmin = []
Fmax = []
for elem in top_plot:
Ftop = [p.__dict__[elem] for p in tws]
Fmin.append(min(Ftop))
Fmax.append(max(Ftop))
greek = ""
if "beta" in elem or "alpha" in elem or "mu" in elem:
greek = "\\"
if "mu" in elem:
elem = elem.replace("mu", "mu_")
top_label = r"$" + greek + elem+"$"
ax.plot(S, Ftop, lw = 2, label=top_label)
d_Ftop.append( max(Ftop) - min(Ftop))
d_F = max(d_Ftop)
if d_F == 0:
d_Dx = 1
ax.set_ylim(( min(Fmin)-d_Dx*0.1, max(Fmax)+d_Dx*0.1))
if top_plot[0] == "E":
top_ylabel = r"$"+"/".join(top_plot) +"$"+ ", [GeV]"
elif top_plot[0] in ["mux", 'muy']:
top_ylabel = r"$" + "/".join(top_plot) + "$" + ", [rad]"
else:
top_ylabel = r"$"+"/".join(top_plot) +"$"+ ", [m]"
yticks = ax.get_yticks()
yticks = yticks[2::2]
ax.set_yticks(yticks)
ax.set_ylabel(top_ylabel, fontsize=font_size)
ax.tick_params(axis='both', labelsize=font_size)
leg2 = ax.legend(loc='upper right', shadow=False, fancybox=True, prop=font_manager.FontProperties(size=font_size))
leg2.get_frame().set_alpha(0.2)
示例14: plot_betas
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def plot_betas(ax, S, beta_x, beta_y, font_size):
ax.set_ylabel(r"$\beta_{x,y}$ [m]", fontsize=font_size)
ax.plot(S, beta_x, 'b', lw=2, label=r"$\beta_{x}$")
ax.plot(S, beta_y, 'r', lw=2, label=r"$\beta_{y}$")
ax.tick_params(axis='both', labelsize=font_size)
leg = ax.legend(loc='upper left', shadow=False, fancybox=True, prop=font_manager.FontProperties(size=font_size))
leg.get_frame().set_alpha(0.2)
示例15: plot_xy
# 需要导入模块: from matplotlib import font_manager [as 别名]
# 或者: from matplotlib.font_manager import FontProperties [as 别名]
def plot_xy(ax, S, X, Y, font_size):
ax.set_ylabel(r"$X, Y$, m")
ax.plot(S, X,'r', lw = 2, label=r"$X$")
ax.plot(S, Y,'b', lw = 2, label=r"$Y$")
leg = ax.legend(loc='upper right', shadow=True, fancybox=True, prop=font_manager.FontProperties(size=font_size))
leg.get_frame().set_alpha(0.5)