如何在matplotlib轴中写入latex特殊字符$\bar{T}$?

2024-09-30 01:37:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在用matplotlib绘制的绘图的axes标签中写入latex数学模式符号$\bar{T}$。documentation声明不支持数学模式,所以我尝试了

plt.xlabel(r'$\displaystyle \={T}$',fontsize=12)

以及

^{pr2}$

这就产生了错误

matplotlib.pyparsing.ParseFatalException: Expected end of math '$'
$\displaystyle \={T}$ (at char 0), (line:1, col:1)

以及

    raise ParseFatalException(msg + "\n" + s)
matplotlib.pyparsing.ParseFatalException: Expected end of math '$'
$\={T}$ (at char 0), (line:1, col:1)
>>> 

有没有办法用matplotlib把这个符号写在轴标签上?我已经能够写其他乳胶轴标签,但我从来没有使用过这些special characters.


Tags: ofmatplotlibline模式符号数学math标签
1条回答
网友
1楼 · 发布于 2024-09-30 01:37:22

链接到的文档页面描述了调用Latex以提供格式化文本,但matplotlib有自己内置的数学表达式解析器,可以很好地处理大多数Latex数学命令,而无需实际运行外部Latex命令。除非您专门将matplotlib安装设置为使用外部安装的Latex,否则您仍然使用内置的数学解析器,它可以处理\bar{}很好:

plt.plot(range(5), range(5))
plt.xlabel(r'$\bar{T}$',fontsize=12)
plt.show()

相关问题 更多 >

    热门问题