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

[Bug]: Rendering bug with no-latex #93

Closed
JBorrow opened this issue May 23, 2023 · 1 comment · Fixed by #94
Closed

[Bug]: Rendering bug with no-latex #93

JBorrow opened this issue May 23, 2023 · 1 comment · Fixed by #94
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers

Comments

@JBorrow
Copy link
Contributor

JBorrow commented May 23, 2023

Environment

System: macOS-13.3.1-arm64-arm-64bit
Python: 3.9.7 (default, Aug 31 2021, 21:51:10)
[Clang 12.0.5 (clang-1205.0.22.9)]
SciencePlots: 2.0.1
Matplotlib: 3.6.2

Describe the issue here

Using the no-latex stylesheet provides very different rendering to those that require a TeX distribution.

Throughout, I will use the following test script:

import matplotlib.pyplot as plt
import scienceplots

plt.style.use([$STYLESHEETS])

plt.plot(range(10), range(10), label="Test")
plt.legend()
plt.xlabel("$x$-axis [Mpc]")
plt.ylabel("$f(x) = \\frac{x}{x^2} x^2$ [Mpc]")

plt.savefig("test.png", dpi=300)

For $STYLESHEETS = "science", we get the following:

test

Where all of the labels are rendered using the default TeX font.

But when using $STYLESHEETS = "science", "no-latex", we get the following:
test

Where the fonts are now replaced by the matplotlib defaults (in this case Dejavu Serif).

In my opinion, the package should strive to keep rendering as close as possible between scenarios where TeX is used and where it is not.

By modifying the no-latex.mplstyle stylesheet to be the following:

# Deactivate LaTeX

text.usetex : False

# Set fonts to be LaTeX defaults
font.serif : cmr10, Computer Modern Serif, DejaVu Serif
font.family : serif
axes.formatter.use_mathtext : True
mathtext.fontset : cm

We can ensure that the rendering looks as close as possible:
test

This should never fail, as cm and cmr10 are TTFs that are bundled with matplotlib itself (they reside in mpl-data).

Now in reality setting the correct fonts should not be the no-latex stylesheet's responsibility.

In particular to remedy this bug you would want to change in science.mplstyle:

font.serif : cmr10, Computer Modern Serif, DejaVu Serif
axes.formatter.use_mathtext : True
mathtext.fontset : dejavuserif

Or if you wanted to use the Times family:

font.family: STIXGeneral
mathtext.fontset: stix
@JBorrow JBorrow added the bug Something isn't working label May 23, 2023
@echedey-ls
Copy link
Collaborator

echedey-ls commented May 23, 2023

I would love to see a PR on this!

Thank you very much for that information.

@echedey-ls echedey-ls added enhancement New feature or request good first issue Good for newcomers labels May 23, 2023
echedey-ls added a commit to echedey-ls/SciencePlots that referenced this issue Nov 25, 2023
Still need to ensure desired behaviour.

Co-Authored-By: Josh Borrow <josh@joshborrow.com>
echedey-ls added a commit that referenced this issue Nov 25, 2023
* Revert "Change font styles to work well without LaTeX  (#94)"

This reverts commit 337e87a.

* Re-refix #30 in accordance to #93

Still need to ensure desired behaviour.

Co-Authored-By: Josh Borrow <josh@joshborrow.com>

---------

Co-authored-by: Josh Borrow <josh@joshborrow.com>
echedey-ls added a commit that referenced this issue Nov 25, 2023
* Even a better fix to #30

Co-Authored-By: Josh Borrow <josh@joshborrow.com>

* Update examples to showcase `no-latex` + `science`

---------

Co-authored-by: Josh Borrow <josh@joshborrow.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants