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

Symbols appear as streaks with usetex=True, times font and PDF backend · Issue #11259 · matplotlib/matplotlib · GitHub

Repository navigation

Symbols appear as streaks with usetex=True, times font and PDF backend #11259

Closed

Description

Bug report

Bug summary

  • Symbols appear as streaks with usetex=True, times font and PDF backend

Code for reproduction

import matplotlib as mpl
import matplotlib.pyplot as plt

mpl.rcParams.update(mpl.rcParamsDefault)
mpl.rcParams['text.usetex'] = True
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['times']

fig, ax = plt.subplots()
ax.set_xlabel(r'$x$ $\alpha$')
fig.savefig('test.pdf')

Actual outcome
test.pdf

  • Alpha symbol in the x-axis label appears as a streak in the output PDF

Expected outcome

  • Alpha symbol in the x-axis label to appear as an alpha, rendered by LaTeX

Matplotlib version

  • Matplotlib 2.2.2, Python 2.7.15, OSX 10.13.4
  • pdfTeX 3.14159265-2.6-1.40.19 (TeX Live 2018), kpathsea version 6.3.0
  • Installed with MacPorts

Activity

  1. jklymak commented on May 16, 2018

    Member

    I can't reproduce MacOS 10.13.4 py 3.6, conda,

    $ latex --version
    pdfTeX 3.14159265-2.6-1.40.18 (TeX Live 2017)
    kpathsea version 6.2.3
    
  2. jklymak commented on May 16, 2018

    Member
  3. jklymak commented on May 16, 2018

    Member

    Oddly, your file is 10 bytes larger than mine. Otherwise I don't see a difference.

  4. pdhall99 commented on May 16, 2018

    Author

    Similar issue described in this comment: #9139 (comment)

  5. jklymak commented on May 16, 2018

    Member

    Agreed. Its strange I can't replicate it - I doubt the latex versions are the issue.

    Did you clear your cache: (on my machine ~/.matplotlib/tex.cache) ? Maybe you had an old alpha in there causing grief?

    You can also look in that directory and see the glyphs you are making... Maybe a clue there..

  6. pdhall99 commented on May 17, 2018

    Author

    Thanks. I have tried clearing the cache, but it didn't help.

    I am not sure how to use the contents of tex.cache to find clues. Are you able to advise?

  7. jklymak commented on May 17, 2018

    Member

    The cache should have all the dvi and png files in it for all the text element s You can check that the alpha one looks correct

  8. pdhall99 commented on May 17, 2018

    Author

    The alpha dvi in tex.cache looks fine.

  9. jklymak commented on May 17, 2018

    Member

    What about the png?

  10. pdhall99 commented on May 17, 2018

    Author

    There is no png. Should there be?

  11. jklymak commented on May 17, 2018

    Member

    Oh, maybe not if you just use the PDF backend. I assume if you add a plt.show() the GUI plot looks OK?

    Are you 100% sure you are using 2.2.2? i.e. can you add

    import matplotlib
    print(matplotlib.__version__)

    to the above script?

    Its strange that our almost-identical setups would behave differently. I suppose I could update TexLive just to be 100% certain...

  12. pdhall99 commented on May 17, 2018

    Author

    The GUI plot looks OK when I add plt.show(), but I get a message:

    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/font_manager.py:1328: UserWarning: findfont: Font family [u'serif'] not found. Falling back to DejaVu Sans
      (prop.get_family(), self.defaultFamily[fontext]))
    

    I am unsure how relevant this is, because the GUI plot and PDF show Times not DejaVu Sans for the tick labels?

    I am using matplotlib 2.2.2. I added the lines you suggested and the output is 2.2.2

  13. pdhall99 commented on May 18, 2018

    Author

    I think the warning is because I only have Times.ttc on my machine, not Times.ttf. I don't think it is relevant to my issue.

  14. pharshalp commented on May 19, 2018

    Contributor

    I can reproduce this issue on Mac OS 10.13.4, Python 3.6.5 :: Anaconda custom (64-bit), Matplotlib 2.2.2, pdfTeX 3.14159265-2.6-1.40.19 (TeX Live 2018)

  15. 7 remaining items

  16. jklymak commented on May 25, 2018

    Member

    Ah, maybe I can't reproduce because I can't find those font families:

    /Users/jklymak/matplotlib/lib/matplotlib/font_manager.py:1220: UserWarning: findfont: Font family ['serif'] not found. Falling back to DejaVu Sans.
      (prop.get_family(), self.defaultFamily[fontext]))
    

    and

    \Users/jklymak/matplotlib/lib/matplotlib/font_manager.py:1220: UserWarning: findfont: Font family ['times'] not found. Falling back to DejaVu Sans.
      (prop.get_family(), self.defaultFamily[fontext]))
    
  17. pharshalp commented on May 25, 2018

    Contributor

    Can anyone produce this not on macOS?

    I tried this in a VM (Ubuntu 18.04) with --
    Python 3.6.5 :: Anaconda custom (64-bit)
    Matplotlib 2.2.2, pdfTeX 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian)
    kpathsea version 6.2.3

    1. with mpl.rcParams['font.serif'] = ['times'] I get the following warning (missing font families).

    anaconda3/lib/python3.6/site-packages/matplotlib/font_manager.py:1328: UserWarning: findfont: Font family ['serif'] not found. Falling back to DejaVu Sans

    1. with mpl.rcParams['font.serif'] = ['times new roman'] I do not get any warning.

    In both cases, the pdf looks fine (with no streaks).

  18. jklymak commented on May 25, 2018

    Member

    Thanks @pharshalp - times new roman works for me as well.

    If anyone wants to figure out where there font is coming from:

    from matplotlib.font_manager import findfont, FontProperties
    font = findfont(FontProperties(family=['times new roman']))
    print(font)
  19. pdhall99 commented on May 26, 2018

    Author

    You can make a more minimal example that produces the error if you only change the following rcParams:

    mpl.rcParams['text.usetex'] = True
    mpl.rcParams['font.serif'] = ['times']

    I find that changing

    mpl.rcParams['text.usetex'] = True
    mpl.rcParams['font.family'] = ['times']

    produces a PDF with all the text is Computer Modern, not Times. As does the following:

    mpl.rcParams['text.usetex'] = True
    mpl.rcParams['font.family'] = ['times new roman']

    A minimal example that avoids the warning that matplotlib can't find Times.ttf but still has the problem displaying alpha:

    import matplotlib as mpl
    import matplotlib.pyplot as plt
    
    mpl.rcParams.update(mpl.rcParamsDefault)
    mpl.rcParams['text.usetex'] = True
    mpl.rcParams['font.serif'] = ['times', 'times new roman']
    
    fig, ax = plt.subplots()
    ax.set_xlabel(r'$x$ $\alpha$')
    fig.savefig('test.pdf')
  20. lboogaard commented on Jun 25, 2018

    Contributor

    Has there been any progress on this? I'm now running into this issue on osx after re-creating a figure that was fine before.

    (Note that, as temporary workaround, one could save as a png.)

  21. pdhall99 commented on Jun 25, 2018

    Author

    If you have the newtxmath package then another workaround that works with PDF output is to add

    mpl.rcParams['text.latex.preamble'] = [r'\usepackage{newtxmath}'] 
  22. astro313 commented on Apr 3, 2019

    I have tried all the solutions above and they solve my problem if I plot and open them on my mac. But the problem persists when I open a file copied from a linux workstation. I've tried installing times.ttf (and make a copy to /anaconda2/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/ttf) and also ~/Library/Fonts (and installing to the system), but the greek letters still appear as streaks in the copied file.

    The greek letters look fine when viewed on the workstation.

  23. jsalort commented on Jul 1, 2019

    * Can anyone produce this _not_ on macOS?
    

    I reproduce it with a figure produced on Debian 4.9.144-3.1 and matplotlib 3.1.0/python 3.7.3 installed from anaconda.

    The figure shows correctly on the PDF Viewer opened by Jupyterlab in the web browser. However, when I save and open the file on the Mac with Preview.app, there is a streak. When I open it in Adobe Reader DC, I get an error message that it is impossible to extract the font "StandardSymL_Slant_167" and that some characters may not show properly. When the figure PDF in included in a LaTeX document, there are streaks.

  24. calvin-sykes commented on Dec 12, 2019

    I was also affected by this issue; somewhat embarrassingly, in a paper uploaded to arXiv.
    The following Ghostscript command (from here) resolved it for me:

    gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dEmbedAllFonts=true -sOutputFile=my_plot_embedded.pdf -f my_plot.pdf

    I had to run this for each figure individually, running the command on the final LaTeX document did not work.

  25. markushartmann commented on Jan 10, 2020

    I reproduced also the error on Mac 10.12.6 mit python 2.7.17 und matplotlib 2.2.4.

    Screenshot Adobe Reader

    Screenshot Preview

  26. spmulders commented on Mar 10, 2020

    I was also affected by this issue; somewhat embarrassingly, in a paper uploaded to arXiv.
    The following Ghostscript command (from here) resolved it for me:

    gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dEmbedAllFonts=true -sOutputFile=my_plot_embedded.pdf -f my_plot.pdf

    I had to run this for each figure individually, running the command on the final LaTeX document did not work.

    This actually works, thanks! On Windows, use gswin64c instead of gs, contained in the bin folder of Ghostscript.

  27. jkseppan commented on Jul 28, 2020

    Member

    I think this could be the same bug as #16087, which should be fixed on current master (by PR #18080).

  28. QuLogic commented on Sep 9, 2020

    Member

    I confirmed on the Mac mini that this is fixed by #18080.

  29. added this to the v3.4.0 milestone on Sep 9, 2020
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

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL