Python: latex not recognized

Question:

I am trying to create a plot in matplotlib where all the labels are in LaTeX. I am using Jupyter Notebook on Fedora 36 and installed LaTeX using !pip install latex. Here is my program:


# importing the required module 
import matplotlib.pyplot as plt 
    
# x axis values 
x = [1,2,3] 
# corresponding y axis values 
y = [2,4,1] 
    
# plotting the points  
plt.plot(x, y) 
    
# naming the x axis 
plt.xlabel('x - axis') 
# naming the y axis 
plt.ylabel('y - axis') 
    
# giving a title to my graph 
plt.title('My first graph!') 

plt.rcParams.update({
    "text.usetex": True,
    "font.family": "monospace"})
    
# function to show the plot 
plt.show() 

Yet, I receive this error:

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

What am I missing here?

Asked By: Dila

||

Answers:

matplotlib doesn’t have a dependency on the python library latex; rather, it has a dependency on LaTeX iself. You need to install LaTeX, see Latex :: Fedora Docs. Since you only want this for rendering matplotlib labels, try this:

sudo dnf install texlive-scheme-basic

If that’s not enough, you could install texlive-scheme-medium or texlive-scheme-full.

Answered By: pigrammer
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.