Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RolandRitt opened this issue Feb 22, 2016 · 3 comments
Closed

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

RolandRitt opened this issue Feb 22, 2016 · 3 comments
Labels
status: inactive Marked by the “Stale” Github Action topic: text/usetex topic: text

Comments

@RolandRitt
Copy link

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

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Feb 22, 2016
@tacaswell
Copy link
Member

attn @mdboom

@mdboom
Copy link
Member

mdboom commented Feb 29, 2016

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

@QuLogic QuLogic modified the milestones: 2.0.1 (next bug fix release), 2.0.2 (next bug fix release) May 3, 2017
@tacaswell tacaswell modified the milestones: 2.1.1 (next bug fix release), 2.2 (next feature release) Oct 9, 2017
@github-actions
Copy link

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!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Mar 22, 2023
@jklymak jklymak closed this as not planned Won't fix, can't repro, duplicate, stale Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: inactive Marked by the “Stale” Github Action topic: text/usetex topic: text
Projects
None yet
Development

No branches or pull requests

6 participants