-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
UnicodeDecodeError when making a plot using the 'classic' style and text.usetex=True #8423
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
Comments
Ah, it works if the bits that interact with matplotlib look like this:
instead of this:
So I guess that explains why no one noticed until now. Unfortunately the way the script runs in the description is more or less how yt is using matplotlib. It's kind of a hack, but it's the only way I could figure out to work around #6518 and make sure yt plots have the same fonts they had under matplotlib 1.5.3. |
I can reproduce this, but do not understand why.... I think the important thing is if the figure (and hence axes and such) are created in the context manager or not. The three obviously relavent rcparams ('text.latex.unicode', 'text.usetex', 'axes.unicode_minus') are the same in the new default and classic mode (or I can not read which is also possible). A workaround might be to set |
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams['text.usetex'] = True
# Example data
t = np.arange(-1.0, 1.0 + 0.01, 0.01)
s = np.cos(4 * np.pi * t) + 2
plt.close('all')
plt.plot(t, s)
with plt.style.context({'text.usetex': True}, 'classic'):
plt.savefig('tex_demo') This behaves as expected, but again, not quite sure why. |
According to the API docs,
|
hmm, I mis-remembered that API then...It is a list of styles, not import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams
rcParams['text.usetex'] = True
# Example data
t = np.arange(-1.0, 1.0 + 0.01, 0.01)
s = np.cos(4 * np.pi * t) + 2
plt.close('all')
plt.plot(t, s)
with plt.style.context(['classic', {'text.usetex': True}]):
plt.savefig('tex_demo') and that order makes more sense! |
FWIW I've mitigated this on the yt side with yt PR 2573 (https://bitbucket.org/yt_analysis/yt/pull-requests/2573). I guess using the classic style just to get the fonts I want was a bit of a blunt instrument. |
text.latex.unicode is now on by default, per #11381 (not on the 2.2.x branch, FWIW).
but I have a fix coming up for that... |
Bug report
When making a plot using the 'classic' style, matplotlib overrides the default value for
text.latex.unicode
, setting it toFalse
. This causes a problem for any plot that has negative numbers in any label, because matplotlib now uses a unicode symbol to represent the negative sign.Code for reproduction
Actual outcome
The following traceback:
Expected outcome
The plot should be saved to disk without erroring. The script runs without error on matplotlib 1.5.3.
Matplotlib version
Matplotlib 2.0.0 on OSX, installed via pip.
The text was updated successfully, but these errors were encountered: