def generate_entries(): fc_format = r"--format=%{file}\n%{family}\n%{slant}\n%{weight}\n%{width}\n" vendored_fonts_dir = Path(mpl.get_data_path(), "fonts/ttf") vendored_fonts = [*map(str, vendored_fonts_dir.glob("*.ttf"))] vendored_fonts = subprocess.check_output(["fc-query", fc_format] + vendored_fonts, universal_newlines=True) system_fonts = subprocess.check_output(["fc-list", fc_format], universal_newlines=True) entries = [] lines = vendored_fonts.splitlines() + system_fonts.splitlines() while lines: fc_file, fc_family, fc_slant, fc_weight, fc_width, *lines = lines file = fc_file families = fc_family.split(",") if re.match("\A\[.*\]\Z", fc_weight): # Variable weight, unsupported. print(f"Skipping {fc_file} (unsupported variable weight)") continue style = {"0": "normal", "100": "italic", "110": "oblique"}[fc_slant] # See FcWeightToOpenType. # Note that 215 ("EXTRABLACK") does not appear in the docs, but in the # header... fc_weights = [0, 40, 50, 55, 75, 80, 100, 180, 200, 205, 210, 215] css_weights = [ 100, 200, 300, 350, 380, 400, 500, 600, 700, 800, 900, 1000 ] weight = int(np.interp(float(fc_weight), fc_weights, css_weights) + .5) # The old version from pango_fc_weight_to_pango was: # weight = ( # 100 if fc_weight <= 20 # else 200 if fc_weight <= 45 # else 300 if fc_weight <= 62 # else 380 if fc_weight <= 77 # else 400 if fc_weight <= 90 # else 500 if fc_weight <= 140 # else 600 if fc_weight <= 190 # else 700 if fc_weight <= 202 # else 800 if fc_weight <= 207 # else 900 if fc_weight <= 212 # else 1000) stretch = { "50": "ultra-condensed", "63": "extra-condensed", "75": "condensed", "87": "semi-condensed", "100": "normal", "113": "semi-expanded", "125": "expanded", "150": "extra-expanded", "200": "ultra-expanded", }[fc_width] variant = "normal" # Small caps not supported. size = "scalable" entries.extend( fm.FontEntry(file, family, style, variant, weight, stretch, size) for family in families) entries.sort(key=lambda entry: entry.fname) return entries
def line2img(line, scores, filename, maxwidth=50, img_width=800): ''' Outputs an image containing text with green/red background highlights to indicate the importance of words in the text. Arguments: line (str): the text that should be printed scores (Tensor): a vector of size len(line), where each index contains the "weight" of the corresponding letter in the line string; positive values will be colored green, and negative values red. filename (str): the name of the output file ''' import matplotlib import matplotlib.colors as colors matplotlib.use('Agg') import matplotlib.pyplot as plt import numpy as np import math import matplotlib.font_manager as font_manager import os font_manager.FontEntry( fname=os.path.expanduser('~/project/fonts/ipag.ttf')) fp = matplotlib.font_manager.FontProperties( fname=os.path.expanduser('~/project/fonts/ipag.ttf')) plt.rcParams['font.family'] = fp.get_name() im_height = 1 + len(line) // maxwidth im = np.zeros([maxwidth, im_height]) for i in range(scores.shape[0]): im[i % maxwidth, im_height - i // maxwidth - 1] = scores[i] cmap = matplotlib.colors.LinearSegmentedColormap.from_list( "", ["red", "white", "green"]) scores_max = torch.max(scores) norm = plt.Normalize(-scores_max, scores_max) dpi = 96 fig, ax = plt.subplots(figsize=(img_width / dpi, 300 / dpi), dpi=dpi) ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) ax.spines['left'].set_visible(False) ax.spines['bottom'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.set_xlim(-0.5, -0.5 + maxwidth) ax.set_ylim(-0.5, 0.5 + i // maxwidth) ax.imshow(im.transpose(), cmap=cmap, norm=norm) #,fontproperties= fp for i, c in enumerate(line): ax.text(i % maxwidth - 0.25, im_height - i // maxwidth - 0.25 - 1, c, fontsize=12, fontproperties=fp) plt.tight_layout() plt.savefig(filename, bbox_inches='tight')
def set_font(path, name): fe = fm.FontEntry(fname=path, name=name) fm.fontManager.ttflist.insert(0, fe) pp.rcParams["font.family"] = fe.name
import platform import matplotlib.pyplot as plt import matplotlib.font_manager as fm os = platform.system() if os == "Darwin": plt.rc('font', family="AppleGothic") else: fe = fm.FontEntry( fname="pykrx/NanumBarunGothic.ttf", name='NanumBarunGothic' ) fm.fontManager.ttflist.insert(0, fe) plt.rc('font', family=fe.name) plt.rcParams['axes.unicode_minus'] = False
count_stats, METRICS_TO_INVERT as invertible_metrics, POSITIONS_DICT as pos_dict, POSITIONS_FBREF_DICT as fbref_pos_dict, POSITIONS_COLORS_DICT as col_dict, SEASON) warnings.filterwarnings("ignore") TEXT_COLOR = "k" LINE_COLOR = "k" SCATTER_COLOR = "k" LABEL_FILL_COLOR = "0.7" MIN_90s = 4 ##for the player comparison pool, not the queried player themself font_name = 'Source-Sans-Pro' font_dirs = ['../Source_Sans_Pro/'] font_file = sorted(font_manager.findSystemFonts(fontpaths=font_dirs))[1] font_list = [font_manager.FontEntry(font_file, name=font_name)] font_manager.fontManager.ttflist.extend(font_list) plt.rcParams['font.family'] = font_name font_prop_italic = font_manager.FontProperties( fname="../Source_Sans_Pro/SourceSansPro-Italic.ttf", size=8) font_prop_bold = font_manager.FontProperties( fname="../Source_Sans_Pro/SourceSansPro-SemiBold.ttf", size=16) def plot_sonar(fig, ax, position, df, player_name, minutes, team_name, season, age): """Creates the pizza plot for a player """ # fig, ax = plt.subplots(figsize=(6,8), subplot_kw={"projection":"polar"})
TP = 98 TC = 109 fname_cats = {AK: 'is_predicted_', AL: 'is_exp_known_', AS: 'is_similar_', K: 'only_predicted_', L: 'only_exp_known_', S: 'only_similar_', LK: 'known_predicted_', SK: 'similar_predicted_'} flav_ids = ['AGI', 'BUN', 'KXN', 'HWB', 'EKXN', 'EGT', 'ERD', 'GKXN', 'GEN', 'HCC', 'KMP', 'LU2', 'MYC', 'NAR', 'QUE'] names = {'AGI': 'Apigenin', 'BUN': 'Butein', 'KXN': 'Catechin', 'HWB': 'Cyanidin', 'EKXN': 'Epicatechin', 'EGT': 'Epigallocatechin', 'ERD': 'Eriodictyol', 'GKXN': 'Gallocatechin', 'GEN': 'Genistein', 'HCC': 'Isoliquiritigenin', 'KMP': 'Kaempferol', 'LU2': 'Luteolin', 'MYC': 'Myricetin', 'NAR': 'Naringenin', 'QUE': 'Quercetin'} fe = fm.FontEntry(fname='nunito/NunitoSans-SemiBold.ttf', name='NunitoSans-Bold') fm.fontManager.ttflist.insert(0, fe) plt.rcParams['font.family'] = fe.name ftype = '.png' def main(): rd = pd.read_excel('kegg-data.xlsx') df = rd[['Name'] + flav_ids] df = df.set_index('Name') mk_tables(df) # vennd(df) def mk_tables(df): try: os.mkdir('pics') except (FileExistsError, OSError) as e: pass try: os.mkdir('csv')