Python 如何在轴标签和图例中用下标书写文本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3985827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 13:42:12 来源:igfitidea点击:
How do I write text in subscript in the axis labels and the legend?
提问by Bruce
I have the following axis labels and legend.
我有以下轴标签和图例。
plt.ylabel("ratio_2")
plt.xlabel("n_1")
plt.legend(('alpha_1','alpha_2' ), loc = 'best',shadow = True)
采纳答案by Jouni K. Sepp?nen
Put dollar signs around the formula: plt.xlabel("$n_1$")
在公式周围加上美元符号: plt.xlabel("$n_1$")
回答by Andrew Walker
The easiest way I know is to enable TeX mode for matplotlib,
我知道的最简单的方法是为 matplotlib 启用 TeX 模式,
from http://www.scipy.org/Cookbook/Matplotlib/UsingTex:
来自http://www.scipy.org/Cookbook/Matplotlib/UsingTex:
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
rc('text', usetex=True)

