import matplotlib as mpl
from matplotlib.backends.backend_pdf import PdfPages
mpl.rcParams['pdf.fonttype']=42
mpl.rcParams['font.family']='WenQuanYi Zen Hei'
with PdfPages('test.pdf') as pdf:
xxxx # plot some figure
pdf.savefig()
#questions/45870858/runtimeerror-failed-to-open-truetype-font-in-matplotlib-backends-pdf-in-python stackoverflow