本文整理汇总了Python中matplotlib.font_manager方法的典型用法代码示例。如果您正苦于以下问题:Python matplotlib.font_manager方法的具体用法?Python matplotlib.font_manager怎么用?Python matplotlib.font_manager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib
的用法示例。
在下文中一共展示了matplotlib.font_manager方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_disp
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import font_manager [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)
示例2: plot_betas
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import font_manager [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)
示例3: plot_xy
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import font_manager [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)
示例4: test_fontinfo
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import font_manager [as 别名]
def test_fontinfo():
import matplotlib.font_manager as font_manager
import matplotlib.ft2font as ft2font
fontpath = font_manager.findfont("Bitstream Vera Sans")
font = ft2font.FT2Font(fontpath)
table = font.get_sfnt_table("head")
assert table['version'] == (1, 0)
示例5: test_afm_kerning
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import font_manager [as 别名]
def test_afm_kerning():
from matplotlib.afm import AFM
from matplotlib.font_manager import findfont
fn = findfont("Helvetica", fontext="afm")
with open(fn, 'rb') as fh:
afm = AFM(fh)
assert afm.string_width_height('VAVAVAVAVAVA') == (7174.0, 718)
示例6: test_fontinfo
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import font_manager [as 别名]
def test_fontinfo():
import matplotlib.font_manager as font_manager
import matplotlib.ft2font as ft2font
fontpath = font_manager.findfont("DejaVu Sans")
font = ft2font.FT2Font(fontpath)
table = font.get_sfnt_table("head")
assert table['version'] == (1, 0)
示例7: test_text_size_binding
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import font_manager [as 别名]
def test_text_size_binding():
from matplotlib.font_manager import FontProperties
matplotlib.rcParams['font.size'] = 10
fp = FontProperties(size='large')
sz1 = fp.get_size_in_points()
matplotlib.rcParams['font.size'] = 100
assert sz1 == fp.get_size_in_points()
示例8: get_chart_font
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import font_manager [as 别名]
def get_chart_font():
names = [f.name for f in matplotlib.font_manager.fontManager.ttflist]
if DEFAULT_WORD_FONT not in names:
return DEFAULT_WORD_FONT_FALLBACK
return DEFAULT_WORD_FONT
示例9: plot_opt_func_reduced
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import font_manager [as 别名]
def plot_opt_func_reduced(lat, tws, top_plot=["Dx"], legend=True, fig_name=None, grid=False, font_size=18):
"""
function for plotting: lattice (bottom section), vertical and horizontal beta-functions (middle section),
other parameters (top section) such as "Dx", "Dy", "E", "mux", "muy", "alpha_x", "alpha_y", "gamma_x", "gamma_y"
lat - MagneticLattice,
tws - list if Twiss objects,
top_plot=["Dx"] - parameters which displayed in top section. Example top_plot=["Dx", "Dy", "alpha_x"]
legend=True - displaying legend of element types in bottom section,
fig_name=None - name of figure,
grid=True - grid
font_size=18 - font size.
"""
if fig_name == None:
fig = plt.figure()
else:
fig = plt.figure(fig_name)
plt.rc('axes', grid=grid)
plt.rc('grid', color='0.75', linestyle='-', linewidth=0.5)
left, width = 0.1, 0.85
rect1 = [left, 0.63, width, 0.3]
rect2 = [left, 0.20, width, 0.43]
rect3 = [left, 0.10, width, 0.10]
ax_top = fig.add_axes(rect1)
ax_b = fig.add_axes(rect2, sharex=ax_top) # left, bottom, width, height
ax_el = fig.add_axes(rect3, sharex=ax_top)
for ax in ax_b, ax_el, ax_top:
if ax != ax_el:
for label in ax.get_xticklabels():
label.set_visible(False)
ax_b.grid(grid)
ax_top.grid(grid)
ax_el.set_yticks([])
ax_el.grid(grid)
fig.subplots_adjust(hspace=0)
beta_x = [p.beta_x for p in tws] # list(map(lambda p:p.beta_x, tws))
beta_y = [p.beta_y for p in tws] # list(map(lambda p:p.beta_y, tws))
D_x = [p.Dx for p in tws] # list(map(lambda p:p.beta_x, tws))
D_y = [p.Dy for p in tws] # list(map(lambda p:p.beta_y, tws))
S = [p.s for p in tws] # list(map(lambda p:p.s, tws))
plt.xlim(S[0], S[-1])
ax_top.set_ylabel(r"$D_{x,y}$ [m]")
ax_top.plot(S, D_x, 'b', lw=2, label=r"$D_{x}$")
ax_top.plot(S, D_y, 'r', lw=2, label=r"$D_{y}$")
leg = ax_top.legend(loc='upper left', shadow=False, fancybox=True, prop=font_manager.FontProperties(size=font_size))
leg.get_frame().set_alpha(0.2)
plot_betas(ax_b, S, beta_x, beta_y, font_size)
plot_elems(fig, ax_el, lat, s_point=S[0], legend=legend, y_scale=0.8)
示例10: plot_init
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import font_manager [as 别名]
def plot_init(self, name, fig_specs=None, save=False):
#add a figure with a single subplot
if save==True:
import matplotlib
matplotlib.use('Agg') # non-interactive backend
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
fontP = FontProperties()
fontP.set_size('small')
self.colors = ['-r','-b','-m','-g']
if self.fig==None:
self.fig = plt.figure(figsize=(8,4))
if fig_specs != None:
# fig_spec is a dictionary of fig adjust specs
self.fig.subplots_adjust(**fig_sepcs)
else:
self.fig.subplots_adjust(left = 0.15, bottom = 0.07,
right = 0.94, top = 0.94,
hspace = 0.14, wspace=0.20)
if type(name) != str:
raise TypeError('name should be a string')
layout = 'grid'
n = len(self.fig.axes)
if layout in ('h', 'horizontal'):
n_rows, n_cols = (1, n+1)
elif layout in ('v', 'vertical'):
n_rows, n_cols = (n+1, 1)
elif layout in ('g', 'grid'):
vector_length=n+1
n_cols = int(np.ceil(np.sqrt(vector_length)))
n_rows = int(np.ceil(vector_length/n_cols))
else:
raise ValueError('Bad layout Value')
for i in range(n):
self.fig.axes[i].change_geometry(n_rows, n_cols, i+1)
self.figsaxe[name] = self.fig.add_subplot(n_rows, n_cols, n+1)