garrettj403 / SciencePlots

Matplotlib styles for scientific plotting
MIT License
6.96k stars 700 forks source link

`ax.xaxis.set_major_locator` will let matplotlib to throw error. #117

Closed cesaryuan closed 3 months ago

cesaryuan commented 3 months ago

Environment

System: Windows-10-10.0.22621-SP0
Python: 3.9.19 (main, May  6 2024, 20:12:36) [MSC v.1916 64 bit (AMD64)]
SciencePlots: 2.1.1
Matplotlib: 3.8.4
LaTeX distro:
TeX is a trademark of the American Mathematical Society.
using bzip2 version 1.0.8, 13-Jul-2019
compiled with curl version 8.4.0; using libcurl/8.4.0 Schannel
compiled with expat version 2.5; using expat_2.5.0
compiled with jpeg version 9.5
compiled with liblzma version 50040002; using 50040002
compiled with libpng version 1.6.39; using 1.6.39
compiled with libressl version LibreSSL 3.8.1; using LibreSSL 3.8.1
compiled with MiKTeX Application Framework version 4.8; using 4.8
compiled with MiKTeX Core version 4.24; using 4.24
compiled with MiKTeX Archive Extractor version 4.1; using 4.1
compiled with MiKTeX Package Manager version 4.10; using 4.10
compiled with uriparser version 0.9.7
compiled with xpdf version 4.04
compiled with zlib version 1.2.13; using 1.2.13

Affected styles

['science', 'ieee']

Describe the issue here

ax.xaxis.set_major_locator will let matplotlib to throw error.

LookupError: An associated PostScript font (required by Matplotlib) could not be found for TeX font 'zptmcm7y' in 'E:/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

How can we replicate it? What have you tried? Please, add a reproducible example

from matplotlib import ticker
import matplotlib.pyplot as plt
import scienceplots

# If we comment out the following line, the code will run without error
plt.style.use(['science', 'ieee'])

fig, ax = plt.subplots()
ax.plot([1, 2, 3])

# If we comment out the following line, the code will run without error
ax.xaxis.set_major_locator(ticker.LinearLocator(numticks=5))

fig.savefig('test.pdf')

Extra info

No response

echedey-ls commented 3 months ago

I'm not able to reproduce the error neither on Windows/Py3.11 nor Ubuntu/Py3.9

You may want to deactivate using LaTeX for the rendering by appending the no-latex style to your styles list. It's important that it's the latest so it can overwrite the usetex config set by the science style.

['science', 'ieee', 'no-latex']

If you investigate any further and find any relevant info about your problem, or even if you fix it, please let us know, in case it helps somebody in the future.

cesaryuan commented 3 months ago

I'm not able to reproduce the error neither on Windows/Py3.11 nor Ubuntu/Py3.9

Hi, thanks for your reply. I just want to know what TeX distribution you use when trying to reproduce. It will help to find out. 😊

cesaryuan commented 3 months ago
  1. I created a pure Windows 11 virtual machine. And install Miktex and Miniconda 3 from scratch. The bug can still be reproduced.
  2. Trying TexLive; it works. So may be we should make a note in Readme that it does not support Miktex?
echedey-ls commented 3 months ago

Good point @cesaryuan

Windows10 / Python 3.11.8 / Matplotlib 3.8.2

> latex
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) (preloaded format=latex)

Ubuntu 22.04 / Python 3.9.18 / Matplotlib 3.7.2

> latex
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian) (preloaded format=latex)

An idea, if you feel confident, is debugging your code and finding which system call made by matplotlib fails. Then try to replicate it in the command line.

echedey-ls commented 3 months ago
  1. I created a pure Windows 11 virtual machine. And install Miktex and Miniconda 3 from scratch. The bug can still be reproduced.

  2. Trying TexLive; it works. So may be we should make a note in Readme that it does not support Miktex?

Nice timing. I'm hesitant to say that SciencePlots does not support MikTex, but rather note that there have been problems with it. It's a problem in the matplotlib side, it doesn't really involve SciencePlots - we only support the styles and distribution of them. Anyway, I will change something in the wiki. Thanks for reporting the solution!

Feel free to close this issue.

cesaryuan commented 3 months ago

I'm hesitant to say that SciencePlots does not support MikTex, but rather note that there have been problems with it.

I alse post a issue on matplotlib repo. Maybe they will find out. 😊

echedey-ls commented 3 months ago

Good note. Quick question, did you check that running the command latex (command line or powershell) was successful before, with the MikTex distro?

cesaryuan commented 3 months ago

Good note. Quick question, did you check that running the command latex (command line or powershell) was successful before, with the MikTex distro?

Yes, I have used MiKTeX for my journal article. It works well.

echedey-ls commented 3 months ago

Since at matplotlib the issue has been acknowledged and we have updated our recommendations, I think we can close this issue.

Thanks @cesaryuan for reporting and investigating!