Matplotlib not using latex font while text.usetex==True

前端 未结 3 1748
遥遥无期
遥遥无期 2020-12-23 13:56

I want to create labels to my plots with the latex computer modern font. However, the only way to persuade matplotlib to use the latex font is by inserting something like:

相关标签:
3条回答
  • 2020-12-23 14:28

    The default Latex font is known as Computer Modern:

    from matplotlib import rc
    import matplotlib.pylab as plt
    
    rc('font', **{'family': 'serif', 'serif': ['Computer Modern']})
    rc('text', usetex=True)
    
    x = plt.linspace(0,5)
    plt.plot(x,plt.sin(x))
    plt.ylabel(r"This is $\sin(x)$", size=20)
    plt.show()
    

    enter image description here

    0 讨论(0)
  • 2020-12-23 14:29

    I am using matplotlib 1.3.1 on Mac OSX, add the following lines in matplotlibrc works for me

    text.usetex : True
    font.family : serif 
    font.serif  : cm
    

    Using = leads to a UserWarning: Illegal line

    0 讨论(0)
  • 2020-12-23 14:52

    The marked answer can be enabled by default by changing a few lines in the matplotlibrc file:

    text.usetex = True
    font.family = serif 
    font.serif = cm
    
    0 讨论(0)
提交回复
热议问题