2

I use MikTeX and try to obtain LaTeX fonts in my matplotlib plots.

However, using the demo code, Jyputer Notebook says that there is no latex,

Failed to process string with tex because latex could not be found 

I try to add into PATH the path to latex.exe, dvipng.exe and ghostscript. Unfortunately, it still does not work. What I do wrong?

If I evaluate the following

import matplotlib.pyplot as plt import numpy as np plt.plot(np.sin(np.arange(0, 10, 0.1)),label=r"$\mathcal{M}=2$") plt.xlabel("x") plt.ylabel("y") plt.legend() 

it returns me the next picture,

enter image description here

So, I see that \mathcal{} command works perfectly, whereas the fonts are not "latex".

1 Answer 1

2

You need to add plt.rc('text', usetex=True).

Sign up to request clarification or add additional context in comments.

4 Comments

As I have mentioned, it does not work. I have added all the variables into the PATH (latex.exe, dvipng.exe & ghostscipt) but matplotlib says that latex could not be found
@ArtemAlexandrov Did you try the different troubleshooting steps? Probably none of them will work for you, since it is not even finding latex. For the PATH variable: make sure to add only the path to the directory, without the executable name.
I will check my PATH variable, thx. Unfortunately, I have not find useful troubleshooting steps in matplotlib documentation. My guess that it can be related to MikTeX but I am not sure
Sorry, I forgot to add the link to the troubleshooting: matplotlib.org/3.1.0/tutorials/text/usetex.html#troubleshooting

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.