python 上的 Latex:\alpha 和 \beta 不起作用?

发布于 2024-12-11 04:14:03 字数 452 浏览 1 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

∞梦里开花 2024-12-18 04:14:03

问题是 \a\b特殊含义

我建议您在任何时候嵌入反斜杠时都使用 原始字符串细绳:

r'$ \alpha 

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:

r'$ \alpha 

樱&纷飞 2024-12-18 04:14:03

除了使用原始字符串(如上面的帖子中提到的)之外,您还可以转义反斜杠。因此输入 \\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.

所有深爱都是秘密 2024-12-18 04:14:03

您好,如果您的 \alpha \beta 不适用于 Latex

use $\alpha$
likewise $\beta$ so on.

希望有用

Hi if your \alpha and \beta don't work on Latex

use $\alpha$
likewise $\beta$ so on.

hope it works

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文