如何让Python显示x上方的横线?

4 投票
2 回答
18590 浏览
提问于 2025-04-18 13:36

我一直在研究数学符号和不同的工具包,但还没找到可以打印出xbar(平均值x)的方法。

我希望能在matplotlib中把xbar当作一个标签来用。

有没有什么建议呢?

谢谢!祝好!

2 个回答

4

如果你在使用jupyter,可以这样做来处理一个字母(x):

$\bar x$   

#or for a string   
$\overline {xyzabc}$   

#note that one $ will give you an inline output and $$...$$ would start  
#a new line after your output
11

如果你想在matplotlib中使用x bar作为标签,可以这样做:

plt.ylabel(r'$\bar{x}$')

撰写回答