Skip to content

Instantly share code, notes, and snippets.

@zesty
Last active August 8, 2020 06:44
Show Gist options
  • Save zesty/c16053143f0362b076bcfbfe8a9677b6 to your computer and use it in GitHub Desktop.
Save zesty/c16053143f0362b076bcfbfe8a9677b6 to your computer and use it in GitHub Desktop.
afm fonts have odd font weights
# inspect the afm fonts
# I punted and went with: matplotlib.font_manager.weight_dict
# see: https://gist.github.com/zesty/de6f872908add8aca3c3a156431baa3b for the pretty stuff
# ref: Commonly used names for CSS font-weight values https://gist.github.com/lukaszgrolik/5849599
import pandas as pd
import matplotlib.font_manager
df = pd.DataFrame(
# [(f.name, f.stretch, f.style, f.variant, f.weight, f.size) for f in matplotlib.font_manager.fontManager.ttflist] +
[(f.name, f.stretch, f.style, f.variant, f.weight, f.size) for f in matplotlib.font_manager.fontManager.afmlist])
df.columns = ['name', 'stretch', 'style', 'variant', 'weight', 'size']
pd.options.display.max_rows = None
for col in df.columns:
if col == 'name':
continue
print(df[col].value_counts())
print()
df.sort_values(['name',"weight", 'style'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment