Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Problem description:
When usinga custom font, saving the figure as pdf format, and then opening the pdf with adobe reader (or many other pdf readers exceptSumatraPDF), some characters don't display correctly.
I use windows 10 operating system. The font is for the Chinese language, and already install intoC:\windows\fonts
Check the font
from matplotlib.font_manager import fontManagerfor f in fontManager.ttflist: if 'Source Han Serif' in f.name: print(f.name, ' : ', f.fname)
Output:
Source Han Serif CN : C:\Windows\Fonts\SourceHanSerifCN-Regular.otfSource Han Serif CN : C:\Windows\Fonts\SourceHanSerifCN-Bold.otf
Generate the figure
Code (a minimal and fully example)
import matplotlib.pyplot as pltfrom matplotlib.font_manager import FontPropertiesplt.text(0.5, 0.5, '图像', ha='center', va='center', fontdict={'family': 'Source Han Serif CN', 'size': 18})plt.savefig('figure_with_font.pdf')plt.savefig('figure_with_font.png')
There will be a warning message:
'SourceHanSerifCN-Regular.otf' cannot be subsetted into a Type 3 font. The entire font will be embedded in the output.
And the output in the notebook and the png format both displays correctly:
But when openfigure_with_font.pdf
with "adobe reader", it displays like:
When I check the document properties, it seems like the font is already embedded in the pdf:
I've tried some other readers, onlySumatra PDF works.
**I'm using: **
- Windows 10
- matplotlib: 3.0.0
And The output pdf file:
Question:
- Can matplotlib save a figure to pdf without embedding the font? Sometimes when saving thousands of figures, it will help to reduce the file size.
- What's wrong with the pdf not displaying correctly?