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

早过忘川 提交于 2021-01-28 05:04:34

问题


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

Thanks for help


回答1:


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



来源:https://stackoverflow.com/questions/26767186/python-matplotlib-how-to-print-one-text-with-different-sizes-in-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!