Python 在matplotlib的注释中格式化数学文本

Python 在matplotlib的注释中格式化数学文本,python,matplotlib,format,Python,Matplotlib,Format,我试图用一些数学文本在我的绘图中编写文本,如 在犯了很多错误之后,比如 >>> plt.annotate(r'$\log_{10}M_{200}={:.2f}$'.format(xc), xy=(0.9, 0.95), xycoords='axes fraction', size=18, color='blue') Traceback (most recent call last): File "<stdin>", line 1, in <module&

我试图用一些
数学
文本在我的绘图中编写文本,如

在犯了很多错误之后,比如

>>> plt.annotate(r'$\log_{10}M_{200}={:.2f}$'.format(xc), xy=(0.9, 0.95), xycoords='axes fraction', size=18, color='blue')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>

IndexError: tuple index out of range

有什么建议吗?

第二个解决方案的格式部分对我来说很好,但如果将数字放在双花括号中,可能会让你的生活更容易摆脱格式:

r'$\log_{{10}}M_{{200}}={:.2f}$'.format(xc)
例如,对于
xc=5
,此输出

$\log_{10}M_{200}=5.00$
$\log_{10}M_{200}=5.00$