Felix Kemmer
Felix Kemmer

Reputation: 35

Python: Matplotlib: how to print ONE text with different sizes in it?

is it possible in matplotlib to have a textbox with different font sizes within one string?

Thanks for help

Upvotes: 3

Views: 2095

Answers (1)

farenorth
farenorth

Reputation: 10771

I don't think this can be done without using the LaTeX text renderer. To use this do,

from matplotlib import rcParams
rcParams['text.usetex'] = True

Then you can print multi-fontsize strings using standard LaTeX syntax, e.g.

from matplotlib import pyplot as plt
ax = plt.axes()
ax.text(0.5, 0.5, r'{\tiny tiny text} normal text {\Huge HUGE TEXT}')

Sometimes the LaTeX font renderer isn't ideal (e.g. note that tick-label fonts are different than normal MPL tick labels), but it is certainly more flexible.

enter image description here

Upvotes: 4

Related Questions