如何在Matplotlib中以f字符串显示LaTeX大括号

如何在Matplotlib中以f字符串显示LaTeX大括号,matplotlib,latex,f-string,Matplotlib,Latex,F String,当我使用f字符串创建标签时,无法在Matplotlib图形中显示LaTeX大括号。比如说 fig, ax = plt.subplots(1, 3, figsize=(12,4), sharey=True) fig.suptitle("$x_n = x_{n-1}^2$, " + f"$x_0={5:.2f}, \,r={6:.2f}, \,n \in {{ 0,\ldots,{7} }}$") 导致 如何在Matplotlib中的f字符串中显示LaTe

当我使用f字符串创建标签时,无法在Matplotlib图形中显示LaTeX大括号。比如说

fig, ax = plt.subplots(1, 3, figsize=(12,4), sharey=True)
fig.suptitle("$x_n = x_{n-1}^2$, " + f"$x_0={5:.2f}, \,r={6:.2f}, \,n \in {{ 0,\ldots,{7} }}$")
导致


如何在Matplotlib中的f字符串中显示LaTeX大括号?

让我们看看f字符串的值是多少

>>> f"$x_0={5:.2f}, \,r={6:.2f}, \,n \in {{ 0,\ldots,{7} }}$"
'$x_0=5.00, \\,r=6.00, \\,n \\in { 0,\\ldots,7 }$'
>>> 
哦,好吧,但这是传递给乳胶!在LaTeX中,大括号是用于分隔组的活动字符,要在格式化方程式中使用文字大括号,需要引用大括号

>>> f"$x_0={5:.2f}, \,r={6:.2f}, \,n \in \{{ 0,\ldots,{7} \}}$"
'$x_0=5.00, \\,r=6.00, \\,n \\in \\{ 0,\\ldots,7 \\}$'
>>> 

当你在评论中提到要更改字体时,你必须更改数学字体,请参见。

如果相关,(a)我也无法产生任何效果,并且(b)我正在使用
%matplotlib小部件
。哇,我没有想到要将转义放在那里;在每对牙套之前!现在我只需要一个字体补丁(用于STIX sans),用于图形的非乳胶部分(例如记号标签)。@orome