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

前端 未结 3 1747
遥遥无期
遥遥无期 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

提交回复
热议问题