8000 axis wrong font embedded when exporting to pdf (usetex=True) · Issue #6041 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
axis wrong font embedded when exporting to pdf (usetex=True) #6041
Closed as not planned
@RolandRitt

Description

@RolandRitt

Hello!
I'm struggeling when exporting figures to pdf using usetex=True:

When i run the following Code:


"""
Demo of a line plot on a polar axis.
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pgf import FigureCanvasPgf
import matplotlib as mpl
mpl.backend_bases.register_backend('pdf', FigureCanvasPgf)
from matplotlib.ticker import OldScalarFormatter, ScalarFormatter


with plt.rc_context({'text.usetex' : True,
                     'font.family' : 'Times New Roman',
                     'font.serif': 'Times New Roman', # --> no error when using Times New Roman
                     'mathtext.fontset' : 'custom',
                     'mathtext.cal' : 'serif:cursive',
                     'mathtext.rm'  : 'serif',
                     'mathtext.tt'  : 'monospace',
                     'mathtext.it'  : 'serif:italic',
                     'mathtext.bf'  : 'serif:bold',
                     'mathtext.sf'  : 'sans',
                     'text.latex.unicode' : True,
                     'pgf.rcfonts'         : True}):
    r = np.arange(0, 3.0, 0.01)
    theta = 2 * np.pi * r
    r = r*1000000
    #ax = plt.subplot(111, projection='polar')
    ax = plt.subplot(111)
    ax.plot(theta, r, color='b', linewidth=3)
    ax.yaxis.major.formatter._useMathText = True
    ax.xaxis.major.formatter._useMathText = True
    ax.grid(True)
    print(ax.get_xaxis().get_major_formatter())
    #ax.xaxis.set_major_formatter(OldScalarFormatter())
    #ax.yaxis.set_major_formatter(OldScalarFormatter())

    #plt.title(r'Some text with latex in it  $10_4 \times \theta = \Phi$')
    plt.savefig(r'Test_text_embedded_on.pdf', papertype='None')
    plt.show()

In the generated pdf Test_text_embedded_on.pdf the desired Times New Roman Font is not embedded, only the default CMR12-font is embedded.

I found out that it has something to do with the ScalarFormatter --> if I uncomment ax.xaxis.set_major_formatter(OldScalarFormatter()) and ax.yaxis.set_major_formatter(OldScalarFormatter()) the ticks changed (not desired) but in this case the TimesNewRoman font is embedded.

Is there a way to fix this to get TimesNewRoman in the Ticks?

My Setup:

Python 3.5
Matplotlib 1.5.1 --> installed with anaconda
Windows 10

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0