Search code examples
pythonmatplotlibscientific-computing

Matplotlib multiline axis text with different font size


How can I change the font size within the same matplotlib's y axis text. In the code below how put the unit (i.e., m4 kg-1 s-1) in smaller font below the name of the variable (i.e., Resistance)?

import matplotlib.pyplot as plt

plt.plot([1], [1])
plt.ylabel('Total resistance\nm$^{4}$ kg$^{-1}$s$^{-1}$', multialignment='center', fontsize=12, labelpad=5)

Solution

  • How about use _:

    pl.plot([1], [1])
    pl.ylabel('Total resistance\n$\\regular_{{m}^{4} kg^{-1}s^{-1}}$', fontsize=20)
    

    Here is the output:

    enter image description here