Closed JBorrow closed 1 year ago
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
Using the no-latex stylesheet provides very different rendering to those that require a TeX distribution.
no-latex
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:
Where all of the labels are rendered using the default TeX font.
But when using $STYLESHEETS = "science", "no-latex", we get the following:
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:
no-latex.mplstyle
# 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:
This should never fail, as cm and cmr10 are TTFs that are bundled with matplotlib itself (they reside in mpl-data).
cm
cmr10
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:
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
I would love to see a PR on this!
Thank you very much for that information.
Environment
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:
For $STYLESHEETS = "science", we get the following:
Where all of the labels are rendered using the default TeX font.
But when using $STYLESHEETS = "science", "no-latex", we get the following:![test](https://github.com/garrettj403/SciencePlots/assets/7839515/80d5c81c-f606-4fb4-9588-8ba2da324613)
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:We can ensure that the rendering looks as close as possible:![test](https://github.com/garrettj403/SciencePlots/assets/7839515/d6672c9e-03df-4a8b-ae1b-37982c115e07)
This should never fail, as
cm
andcmr10
are TTFs that are bundled with matplotlib itself (they reside inmpl-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
:Or if you wanted to use the Times family: