Skip to content

Instantly share code, notes, and snippets.

@korakot
Last active June 30, 2022 05:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save korakot/9d7f5db632351dc92607fdec72a4953f to your computer and use it in GitHub Desktop.
Save korakot/9d7f5db632351dc92607fdec72a4953f 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})
@korakot
Copy link
Author

korakot commented Jan 11, 2019

You can also install Thai fonts using apt:

!apt install fonts-thai-tlwg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment