Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Characters doesn't display correctly when figure saved as pdf with a custom font #12636

Closed
@gepcel

Description

@gepcel

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:
figure_with_font

But when openfigure_with_font.pdf with "adobe reader", it displays like:
image

When I check the document properties, it seems like the font is already embedded in the pdf:
image

I've tried some other readers, onlySumatra PDF works.

**I'm using: **

  1. Windows 10
  2. matplotlib: 3.0.0

And The output pdf file:

figure_with_font.pdf

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp