Last active
June 30, 2022 05:18
-
-
Save korakot/9d7f5db632351dc92607fdec72a4953f to your computer and use it in GitHub Desktop.
Add thai font on Google Colaboratory notebook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def font_name(filename): | |
from matplotlib.ft2font import FT2Font | |
font = FT2Font(filename) | |
return font.family_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
You can also install Thai fonts using
apt
:!apt install fonts-thai-tlwg