Skip to content

Using fonttype 42 will make the produced PDF size considerably larger when the image has Chinese characters #11303

@jdhao

Description

@jdhao

Description

I want to produce a pdf format image to include in my LaTeX document. The image contains some Chinese characters. I have found that using Chinese characters with fonttype 42 will produce pdf files with greater file size.

The code to reproduce is

import matplotlib.font_manager as mfm
import matplotlib.pyplot as plt
import matplotlib as mpl

font_path = "C:/Windows/fonts/simhei.ttf"
prop = mfm.FontProperties(fname=font_path)
mpl.rcParams['pdf.fonttype'] = 42

ch = False
fig, ax = plt.subplots()

if ch:
	ax.text(0.5, 0.5, "你好", transform=ax.transAxes, fontproperties=prop,
		fontsize=30)
else:
	ax.text(0.5, 0.5, "hello", transform=ax.transAxes, fontsize=30)

plt.savefig("mpl_use_ch.pdf", bbox_inches='tight')
plt.show()

If I set ch=True, the size of produced pdf is 5327k. Otherwise, the size of produced pdf is 374k.

When I comment out the line mpl.rcParams['pdf.fonttype'] = 42, then the produced pdf size is more or less the same no matter I use ch=True or ch=False.

Is this the expected behaviour? Why does using fonttype 42 make the produce pdf size so large?

Versions

  • Operating system: Windows 10
  • Matplotlib version: 2.1.2
  • Python version: 3.6.4

The matplotlib package is installed using conda.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions