FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

axis wrong font embedded when exporting to pdf (usetex=True) · Issue #6041 · matplotlib/matplotlib · GitHub

Repository navigation

axis wrong font embedded when exporting to pdf (usetex=True) #6041

Closed as not planned

Description

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

Activity

  1. added this to the milestone on Feb 22, 2016
  2. tacaswell commented on Feb 22, 2016

    Member

    attn @mdboom

  3. mdboom commented on Feb 29, 2016

    Member

    When text.usetex is True, the matplotlib font settings are largely ignored, and fonts must be controlled by creating a LaTeX preamble.

  4. modified the milestones: , on May 3, 2017
  5. modified the milestones: , on Oct 9, 2017
  6. github-actions commented on Mar 22, 2023

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL