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
https://stackoverflow.com/questions/51810908/custom-fonts-in-google-colaboratory-matplotlib-charts
https://colab.research.google.com/drive/15kcRpv9wkLO2vxWux_gzobVcPuIoJ14r