Search code examples
matplotlibsymbolsmathematical-expressions

Trying to put per mille symbol into plot label usinf matplotlib


I can't figure out how to put the per mille symbol into my plt.ylabel. anyone know how?

    import numpy as np  
    import matplotlib.pyplot as plt
    plt.plot(x,y)

    ax = plt.gca()
    ax.invert_yaxis()

    plt.title("LR04 Benthic $\delta^{18}$O")
    plt.xlabel("Years (ka)")
    plt.ylabel("Benthic $\delta^{18}O (TRYING TO PUT PERMIL SYMBOL HERE)$")
    plt.show()

Solution

  • One possible solution:

    import numpy as np  
    import matplotlib.pyplot as plt
    
    x = np.linspace(-5, 5)
    y = np.cos(x)
    fig, ax = plt.subplots()
    ax.plot(x, y)
    ax.invert_yaxis()
    
    ax.set_title("LR04 Benthic $\delta^{18}$O")
    ax.set_xlabel("Years (ka)")
    ax.set_ylabel("Benthic $^o/_{oo}$")
    plt.show()