Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 910
gcamargo Avatar asked May 16 '26 04:05

gcamargo


1 Answers

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

like image 58
HYRY Avatar answered May 17 '26 18:05

HYRY