Skip to content

Instantly share code, notes, and snippets.

@andjc
Forked from korakot/thai_font.py
Created September 20, 2021 08:13
Show Gist options
  • Save andjc/3ecb47e3d98c25a10250c99eb5ede15b to your computer and use it in GitHub Desktop.
Save andjc/3ecb47e3d98c25a10250c99eb5ede15b to your computer and use it in GitHub Desktop.
Add thai font on Google Colaboratory notebook
!wget https://github.com/Phonbopit/sarabun-webfont/raw/master/fonts/thsarabunnew-webfont.ttf
# !pip install -U --pre matplotlib
import matplotlib as mpl
mpl.font_manager.fontManager.addfont('thsarabunnew-webfont.ttf') # 3.2+
mpl.rc('font', family='TH Sarabun New')
!wget -q http://www.arts.chula.ac.th/ling/wp-content/uploads/TH-Sarabun_Chula1.1.zip -O font.zip
!unzip -qj font.zip TH-Sarabun_Chula1.1/THSarabunChula-Regular.ttf
# !pip install -U --pre matplotlib
import matplotlib as mpl
mpl.font_manager.fontManager.addfont('THSarabunChula-Regular.ttf')
mpl.rc('font', family='TH Sarabun Chula')
def font_name(filename):
from matplotlib.ft2font import FT2Font
font = FT2Font(filename)
return font.family_name
import matplotlib.pyplot as plt
plt.text(0.1, 0.8, 'อักษรไทยน้อย', {'size': 30})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment