python 上的 Latex:\alpha 和 \beta 不起作用?
我使用 matplotlib 来生成一些图形,并使用乳胶作为图例。
更具体地说,我正在尝试使用类似这样的东西:
loglog(x,x, '-r',label='$ \alpha $')
legend()
show()
但是,此代码不会在图形上显示图例,并且在关闭图像后会出现错误。
我正在使用 enthought 包(适用于 mac),但错误来自 pylab/scipy.
出现的错误正是:
$ lpha $ (at char 0), (line:1, col:1)
但是,如果使用 \mu 或 \gamma,效果很好!我只在 \beta 和 \alpha 上发现了这个问题。
有谁知道这可能是什么?我相信 python 将“\a”解释为某个字符......但我不知道应该如何调试/避免它。
I'm using matplotlib to produce some graphics, and I'm using latex for the legends.
More specifically, I'm trying to use something like this:
loglog(x,x, '-r',label='$ \alpha
However, this code does not present a legend on the figure, and gets error after I close the image.
I'm using the enthought package (for mac), but the error comes from the pylab/scipy.
The error the appears is exactly:
$ lpha $ (at char 0), (line:1, col:1)
However, if use the \mu or \gamma, it works well!! I only found about this problem on \beta and \alpha.
Does anyone knows what this can be? I believe python is interpreting "\a" as some character... but I don't know how should I debug / avoid it.
)
legend()
show()
However, this code does not present a legend on the figure, and gets error after I close the image.
I'm using the enthought package (for mac), but the error comes from the pylab/scipy.
The error the appears is exactly:
However, if use the \mu or \gamma, it works well!! I only found about this problem on \beta and \alpha.
Does anyone knows what this can be? I believe python is interpreting "\a" as some character... but I don't know how should I debug / avoid it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是
\a
和\b
有 特殊含义。我建议您在任何时候嵌入反斜杠时都使用 原始字符串细绳:
The issue is that
\a
and\b
have special meaning inside a Python string literal.I recommend that you use raw strings whenever there is a backslash embedded inside a string:
除了使用原始字符串(如上面的帖子中提到的)之外,您还可以转义反斜杠。因此输入
\\alpha
和\\beta
也可以。In addition to using raw strings (as mentioned in the post above) you can also escape the backslash. So typing
\\alpha
and\\beta
will also work.您好,如果您的
\alpha
和\beta
不适用于 Latex希望有用
Hi if your
\alpha
and\beta
don't work on Latexhope it works