Skip to content

Instantly share code, notes, and snippets.

@korakot
Last active September 26, 2022 08:13
Show Gist options
  • Select an option

  • Save korakot/3021b0027607b8102d98faee3a7e156a to your computer and use it in GitHub Desktop.

Select an option

Save korakot/3021b0027607b8102d98faee3a7e156a to your computer and use it in GitHub Desktop.
Set matplotlib to Thai font on MacOS
# download font file มาก่อน
!wget https://awards.opdc.go.th/awards_opdc/assets/fonts/THSarabunNew/THSarabunNew.ttf
# import and install
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
font_list = fm.createFontList(['THSarabunNew.ttf'])
fm.fontManager.ttflist.extend(font_list)
# set font
plt.rcParams['font.family'] = 'TH Sarabun New'
plt.rcParams['xtick.labelsize'] = 20.0
plt.rcParams['ytick.labelsize'] = 20.0
# plot
plt.bar(['ก','ข','ค'], [1,2,3]);
import matplotlib
matplotlib.rc('font', family='Ayuthaya') # MacOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment