Python matplotlib.font_manager() Examples
The following are 17 code examples for showing how to use matplotlib.font_manager(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
matplotlib
, or try the search function
.
Example 1
Project: ocelot Author: ocelot-collab File: accelerator.py License: GNU General Public License v3.0 | 5 votes |
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)
Example 2
Project: ocelot Author: ocelot-collab File: accelerator.py License: GNU General Public License v3.0 | 5 votes |
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)
Example 3
Project: ocelot Author: ocelot-collab File: accelerator.py License: GNU General Public License v3.0 | 5 votes |
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)
Example 4
Project: neural-network-animation Author: miloharper File: test_mathtext.py License: MIT License | 5 votes |
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)
Example 5
Project: neural-network-animation Author: miloharper File: test_text.py License: MIT License | 5 votes |
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)
Example 6
Project: python3_ios Author: holzschu File: test_mathtext.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example 7
Project: python3_ios Author: holzschu File: test_text.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example 8
Project: python3_ios Author: holzschu File: test_text.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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()
Example 9
Project: dockerfiles Author: demisto File: utils.py License: MIT License | 5 votes |
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
Example 10
Project: coffeegrindsize Author: jgagneastro File: test_mathtext.py License: MIT License | 5 votes |
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)
Example 11
Project: coffeegrindsize Author: jgagneastro File: test_text.py License: MIT License | 5 votes |
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)
Example 12
Project: coffeegrindsize Author: jgagneastro File: test_text.py License: MIT License | 5 votes |
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()
Example 13
Project: twitter-stock-recommendation Author: alvarobartt File: test_mathtext.py License: MIT License | 5 votes |
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)
Example 14
Project: twitter-stock-recommendation Author: alvarobartt File: test_text.py License: MIT License | 5 votes |
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)
Example 15
Project: twitter-stock-recommendation Author: alvarobartt File: test_text.py License: MIT License | 5 votes |
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()
Example 16
Project: ocelot Author: ocelot-collab File: accelerator.py License: GNU General Public License v3.0 | 4 votes |
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)
Example 17
Project: Theano-MPI Author: uoguelph-mlrg File: recorder.py License: Educational Community License v2.0 | 4 votes |
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)