Ano*_*ode 5 python plot latex matplotlib
我想在用 matplotlib 绘制的图的轴标签中写入乳胶数学模式符号 $\bar{T}$ 。文档指出不支持数学模式,所以我尝试了
plt.xlabel(r'$\displaystyle \={T}$',fontsize=12)
Run Code Online (Sandbox Code Playgroud)
和
plt.xlabel(r'$\={T}$',fontsize=12)
Run Code Online (Sandbox Code Playgroud)
这给出了错误
matplotlib.pyparsing.ParseFatalException: Expected end of math '$'
$\displaystyle \={T}$ (at char 0), (line:1, col:1)
Run Code Online (Sandbox Code Playgroud)
和
raise ParseFatalException(msg + "\n" + s)
matplotlib.pyparsing.ParseFatalException: Expected end of math '$'
$\={T}$ (at char 0), (line:1, col:1)
>>>
Run Code Online (Sandbox Code Playgroud)
有没有办法使用 matplotlib 在轴标签中写入此符号?我已经能够编写其他乳胶轴标签,但我从未使用过任何这些特殊字符。
您链接到的文档页面描述了调用 Latex 来提供格式化文本,但 matplotlib 有自己的内置数学表达式解析器,可以很好地处理大多数 Latex 数学命令,而无需实际运行外部 Latex 命令。除非您专门将 matplotlib 安装设置为使用 Latex 的外部安装,否则您仍然使用内置的数学解析器,它可以\bar{}
很好地处理:
plt.plot(range(5), range(5))
plt.xlabel(r'$\bar{T}$',fontsize=12)
plt.show()
Run Code Online (Sandbox Code Playgroud)