Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 358
Felix Kemmer Avatar asked Mar 17 '26 11:03

Felix Kemmer


1 Answers

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

like image 146
farenorth Avatar answered Mar 20 '26 09:03

farenorth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!