gpt4 book ai didi

python - 如何在 PyX 中做天文符号 "\sun"

转载 作者:太空宇宙 更新时间:2023-11-03 15:22:42 26 4
gpt4 key购买 nike

我一直在尝试使用 PyX 将太阳的天文符号放在图表上,但没有成功。我的代码如下:

 from pyx import *
from pylab import *
x=arange(1,5,0.1)
y=exp(-(x-3.0)**2/(2.0*0.5**2))/sqrt(2.0*pi*0.5**2)
######################
g=graph.graphxy(width=8,y=graph.axis.linear(title=r"Fraction of DM halos"),x=graph.axis.linear(min=1,title=r"Mass ($10^{11}M_{\sun}$)"))
g.plot(graph.data.values(x=x,y=y),styles=[graph.style.histogram()])
g.writeEPSfile("testhistogram")

我尝试添加 text.set(mode="latex"),然后添加 text.preamble("\usepackage{mathabx}"),但这并没有工作(因为我知道这个符号在 mathabx LaTeX 包上)。有什么想法吗?

最佳答案

我这里没有 pyx,但是你有没有简单地尝试使用 Unicode 字符串并传入你想要的符号的unicode字符?

太阳符号的字符具有 Unicode 编号 9737(十进制,0x2609 十六进制),因此您可以尝试这样做:

g=graph.graphxy(width=8,y=graph.axis.linear(title=r"Fraction of DM halos"),
x=graph.axis.linear(min=1,
title=u"Mass ($10^{11}M_\u2609$)"))

关于python - 如何在 PyX 中做天文符号 "\sun",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12486778/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com