อาการเหล่านี้จะหมดไป โอ้ย!! เมื่อ matplotlib แสดงภาษาไทยไม่ได้ แสดงออกมาเป็นแต่รูปสี่เหลี่ยม ไม่ว่าจะเป็นกราฟ จะเป็น title ก็อ่านไม่ออกเลย
Base on Macbook M1 (สำหรับเครื่อง macbook m1)
import matplotlib
import matplotlib.font_manager as fmfrom os import path
if not path.exists('Sarabun-Regular.ttf'):
!wget https://github.com/google/fonts/raw/main/ofl/sarabun/Sarabun-Regular.ttf -O Sarabun-Regular.ttf
แล้วก็ต่อด้วย
if 'Sarabun' not in [x.name for x in matplotlib.font_manager.fontManager.ttflist]:
matplotlib.font_manager.fontManager.addfont('Sarabun-Regular.ttf')
matplotlib.rc('font', family='Sarabun')
หากเป็น co lab ละ ก็มีเหมือนกัน