Giter Club home page Giter Club logo

Comments (6)

anntzer avatar anntzer commented on June 16, 2024 1

Thanks. I have repro'd the issue (you can also install miktex on mac/linux) and the fix is not obvious :/

from matplotlib.

anntzer avatar anntzer commented on June 16, 2024
  1. Do you get the same error with the following?
from matplotlib import ticker
import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.rcParams['font.family'] = 'serif'
plt.rcParams['font.serif'] = 'Times'

plt.figtext(.5, .5, "$-1$")

fig.savefig('test.pdf')
  1. In either case, insert plt.set_loglevel("debug") immediately after setting the rcparams and re-run the failing code. In the output you should see lines of the form DEBUG:matplotlib.dviread:Dvi: /path/to/.matplotlib/tex.cache/bd/69/bd69c059493a3cf42a641ebfa844039e.dvi (with a different filename). (If the code in 1) also fails for you it may be easier to use it as there will be fewer files to try.) For each such dvi file, try running from the terminal (not python) python -m matplotlib.dviread /path/to/the/dvifile.dvi and post the output.

from matplotlib.

cesaryuan avatar cesaryuan commented on June 16, 2024

@anntzer Thanks so much for you reply.

  1. Also get the same error.

  2. original output

(all) PS D:\user\Desktop\matplotlib-bug> & D:/scoop/apps/miniconda3/current/envs/all/python.exe d:/user/Desktop/matplotlib-bug/bug.py
DEBUG:matplotlib.pyplot:Loaded backend tkagg version 8.6.
DEBUG:matplotlib.texmanager:family: serif, font: Times, info: \usepackage{mathptmx}
DEBUG:matplotlib.texmanager:DejaVu Sans font is not compatible with usetex.
DEBUG:matplotlib.texmanager:Bitstream Vera Sans font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: sans-serif, font: Computer Modern Sans Serif, info: \usepackage{type1ec}
DEBUG:matplotlib.texmanager:Apple Chancery font is not compatible with usetex.
DEBUG:matplotlib.texmanager:Textile font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: cursive, font: Zapf Chancery, info: \usepackage{chancery}
DEBUG:matplotlib.texmanager:DejaVu Sans Mono font is not compatible with usetex.
DEBUG:matplotlib.texmanager:Bitstream Vera Sans Mono font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: monospace, font: Computer Modern Typewriter, info: \usepackage{type1ec}
DEBUG:matplotlib.dviread:Dvi: C:\Users\cesar\.matplotlib\tex.cache\28\05\280592a6cb87d0a6f07f2be6c239ff4c.dvi
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: header=l3backend-dvips.pro
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt
DEBUG:matplotlib.dviread:opening tfm file D:/scoop/apps/miktex/current/texmfs/install/fonts/tfm/adobe/times/ptmr7t.tfm
DEBUG:matplotlib.dviread:lh=18, bc=0, ec=170, nw=21, nh=16, nd=16
DEBUG:matplotlib.dviread:Dvi: D:/scoop/apps/miktex/current/texmfs/install/fonts/vf/adobe/times/ptmr7t.vf
DEBUG:matplotlib.dviread:opening tfm file D:/scoop/apps/miktex/current/texmfs/install/fonts/tfm/adobe/times/ptmr8r.tfm
DEBUG:matplotlib.dviread:lh=18, bc=1, ec=255, nw=34, nh=16, nd=16
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `Gamma'
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `Delta'
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `Theta'
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `Lambda'
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `Xi'
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `Pi'
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `Sigma'
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `Upsilon'
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `Phi'
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `Psi'
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `Omega'
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `dotlessj'
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `lslashslash'
DEBUG:matplotlib.texmanager:family: serif, font: Times, info: \usepackage{mathptmx}
DEBUG:matplotlib.texmanager:DejaVu Sans font is not compatible with usetex.
DEBUG:matplotlib.texmanager:Bitstream Vera Sans font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: sans-serif, font: Computer Modern Sans Serif, info: \usepackage{type1ec}
DEBUG:matplotlib.texmanager:Apple Chancery font is not compatible with usetex.
DEBUG:matplotlib.texmanager:Textile font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: cursive, font: Zapf Chancery, info: \usepackage{chancery}
DEBUG:matplotlib.texmanager:DejaVu Sans Mono font is not compatible with usetex.
DEBUG:matplotlib.texmanager:Bitstream Vera Sans Mono font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: monospace, font: Computer Modern Typewriter, info: \usepackage{type1ec}
DEBUG:matplotlib.dviread:Dvi: C:\Users\cesar\.matplotlib\tex.cache\af\1f\af1f4e0a95d1cb3284108346197a266e.dvi
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: header=l3backend-dvips.pro
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt
DEBUG:matplotlib.dviread:opening tfm file D:/scoop/apps/miktex/current/texmfs/install/fonts/tfm/adobe/times/zptmcm7y.tfm
DEBUG:matplotlib.dviread:lh=18, bc=0, ec=127, nw=45, nh=16, nd=16
DEBUG:matplotlib.dviread:Dvi: D:/scoop/apps/miktex/current/texmfs/install/fonts/vf/adobe/times/zptmcm7y.vf
DEBUG:matplotlib.dviread:opening tfm file D:/scoop/apps/miktex/current/texmfs/install/fonts/tfm/public/cm/cmsy10.tfm
DEBUG:matplotlib.dviread:lh=18, bc=0, ec=127, nw=44, nh=15, nd=16
DEBUG:matplotlib.dviread:opening tfm file D:/scoop/apps/miktex/current/texmfs/install/fonts/tfm/adobe/symbol/psyr.tfm
DEBUG:matplotlib.dviread:lh=17, bc=32, ec=254, nw=52, nh=16, nd=16
DEBUG:matplotlib.dviread:opening tfm file D:/scoop/apps/miktex/current/texmfs/install/fonts/tfm/adobe/times/zptmcm7t.tfm
DEBUG:matplotlib.dviread:lh=18, bc=0, ec=170, nw=33, nh=16, nd=16
DEBUG:matplotlib.dviread:Dvi: D:/scoop/apps/miktex/current/texmfs/install/fonts/vf/adobe/times/zptmcm7t.vf
DEBUG:matplotlib.dviread:opening tfm file D:/scoop/apps/miktex/current/texmfs/install/fonts/tfm/public/cm/cmr10.tfm
DEBUG:matplotlib.dviread:lh=18, bc=0, ec=127, nw=36, nh=16, nd=10
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `dotlessj'
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: Warning: missing glyph `lslashslash'
DEBUG:matplotlib.texmanager:family: serif, font: Times, info: \usepackage{mathptmx}
DEBUG:matplotlib.texmanager:DejaVu Sans font is not compatible with usetex.
DEBUG:matplotlib.texmanager:Bitstream Vera Sans font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: sans-serif, font: Computer Modern Sans Serif, info: \usepackage{type1ec}
DEBUG:matplotlib.texmanager:Apple Chancery font is not compatible with usetex.
DEBUG:matplotlib.texmanager:Textile font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: cursive, font: Zapf Chancery, info: \usepackage{chancery}
DEBUG:matplotlib.texmanager:DejaVu Sans Mono font is not compatible with usetex.
DEBUG:matplotlib.texmanager:Bitstream Vera Sans Mono font is not compatible with usetex.
DEBUG:matplotlib.texmanager:family: monospace, font: Computer Modern Typewriter, info: \usepackage{type1ec}
DEBUG:matplotlib.dviread:Dvi: C:\Users\cesar\.matplotlib\tex.cache\af\1f\af1f4e0a95d1cb3284108346197a266e.dvi
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: header=l3backend-dvips.pro
DEBUG:matplotlib.dviread:Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt
DEBUG:matplotlib.dviread:Dvi: D:/scoop/apps/miktex/current/texmfs/install/fonts/vf/adobe/times/zptmcm7y.vf
Traceback (most recent call last):
  File "d:\user\Desktop\matplotlib-bug\bug.py", line 10, in <module>
    plt.savefig('test.pdf')
  File "D:\scoop\apps\miniconda3\current\envs\all\lib\site-packages\matplotlib\pyplot.py", line 1134, in savefig
    res = fig.savefig(*args, **kwargs)  # type: ignore[func-returns-value]
  File "D:\scoop\apps\miniconda3\current\envs\all\lib\site-packages\matplotlib\figure.py", line 3390, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "D:\scoop\apps\miniconda3\current\envs\all\lib\site-packages\matplotlib\backend_bases.py", line 2193, in print_figure
    result = print_method(
  File "D:\scoop\apps\miniconda3\current\envs\all\lib\site-packages\matplotlib\backend_bases.py", line 2043, in <lambda>
    print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
  File "D:\scoop\apps\miniconda3\current\envs\all\lib\site-packages\matplotlib\backends\backend_pdf.py", line 2807, in print_pdf
    self.figure.draw(renderer)
  File "D:\scoop\apps\miniconda3\current\envs\all\lib\site-packages\matplotlib\artist.py", line 95, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
  File "D:\scoop\apps\miniconda3\current\envs\all\lib\site-packages\matplotlib\artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
  File "D:\scoop\apps\miniconda3\current\envs\all\lib\site-packages\matplotlib\figure.py", line 3154, in draw
    mimage._draw_list_compositing_images(
  File "D:\scoop\apps\miniconda3\current\envs\all\lib\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
    a.draw(renderer)
  File "D:\scoop\apps\miniconda3\current\envs\all\lib\site-packages\matplotlib\artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
  File "D:\scoop\apps\miniconda3\current\envs\all\lib\site-packages\matplotlib\text.py", line 793, in draw
    textrenderer.draw_tex(gc, x, y, clean_line,
  File "D:\scoop\apps\miniconda3\current\envs\all\lib\site-packages\matplotlib\backends\backend_pdf.py", line 2267, in draw_tex
    pdfname = self.file.dviFontName(dvifont)
  File "D:\scoop\apps\miniconda3\current\envs\all\lib\site-packages\matplotlib\backends\backend_pdf.py", line 938, in dviFontName
    psfont = tex_font_map[dvifont.texname]
  File "D:\scoop\apps\miniconda3\current\envs\all\lib\site-packages\matplotlib\dviread.py", line 905, in __getitem__
    raise LookupError(
LookupError: An associated PostScript font (required by Matplotlib) could not be found for TeX font 'zptmcm7y' in 'D:/scoop/apps/miktex/current/texmfs/data/fonts/map/pdftex/pdftex.map'; this problem can often be solved by installing a suitable PostScript font package in your TeX package manager

matplotlib.dviread output:

(all) PS D:\user\Desktop\matplotlib-bug> python -m matplotlib.dviread C:\Users\cesar\.matplotlib\tex.cache\28\05\280592a6cb87d0a6f07f2be6c239ff4c.dvi
=== new page === (w: 509863, h: 444328, d: 141880)
font: 'ptmr8r'  scale: 0.625
x       y       glyph   chr     w       (glyphs)
983040  1441792 108     l       182183
1165223 1441792 112     p       327680
(all) PS D:\user\Desktop\matplotlib-bug> python -m matplotlib.dviread C:\Users\cesar\.matplotlib\tex.cache\af\1f\af1f4e0a95d1cb3284108346197a266e.dvi
=== new page === (w: 836888, h: 444328, d: 54392)
font: 'zptmcm7y'        scale: 0.625
x       y       glyph   chr     w       (glyphs)
983040  1441792 0       .       509208
font: 'ptmr8r'  scale: 0.625
x       y       glyph   chr     w       (glyphs)
1492248 1441792 49      1       327680

from matplotlib.

cesaryuan avatar cesaryuan commented on June 16, 2024

Updates: I created a pure Windows 11 virtual machine. And install MiKTeX and Miniconda 3 from scratch. The bug can still be reproduced.

Then, I tried TexLive, and it works. So the bug is that MiKTeX does not work well with Matplotlib?

from matplotlib.

anntzer avatar anntzer commented on June 16, 2024

Possibly, though we should still try to fix that! I suspect this may be due to misconfiguration on your side (so perhaps the fix would be a better error message), but will need to investigate more (likely not in the very short term).

from matplotlib.

cesaryuan avatar cesaryuan commented on June 16, 2024

I suspect this may be due to misconfiguration on your side.

For this, I created a virtual machine with VMware (to control variables, I'm even using the English Windows version instead of the locale one I'm on). Install MiKTex and Python with its official installer.

VMware reproduce steps:

  1. create Window 11 vm by its iso: https://software.download.prss.microsoft.com/dbazure/Win11_23H2_English_x64v2.iso
  2. install Python: https://www.python.org/downloads/release/python-3119/
  3. install MiKTeX: https://miktex.org/download
  4. check miktex updates and install updates
  5. pip install matplotlib
  6. python bug.py
from matplotlib import ticker
import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.rcParams['font.family'] = 'serif'
plt.rcParams['font.serif'] = 'Times'
# plt.set_loglevel("debug")
plt.figtext(.5, .5, "$-1$")

plt.savefig('test.pdf')

I compare the dvi file generated by texlive and miktex. Here is the result:
MiKTeX: (another thing to be noted is I can compile to pdf successfully by MiKTeX.)

=== new page === (w: 836888, h: 444328, d: 54392)
font: 'zptmcm7y'        scale: 0.625
x       y       glyph   chr     w       (glyphs)
983040  1441792 0       .       509208
font: 'ptmr8r'  scale: 0.625
x       y       glyph   chr     w       (glyphs)
1492248 1441792 49      1       327680

TeXLive:

=== new page === (w: 836888, h: 444328, d: 0)
font: 'cmsy10'  scale: 0.625
x       y       glyph   chr     w       (glyphs)
983040  1441792 0       .       509726
font: 'ptmr8r'  scale: 0.625
x       y       glyph   chr     w       (glyphs)
1492248 1441792 49      1       327680

image

from matplotlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.