gcamargo
gcamargo

Reputation: 3961

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)

Upvotes: 3

Views: 2275

Answers (1)

HYRY
HYRY

Reputation: 97261

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

Upvotes: 8

Related Questions