本文介绍了在Python图中键入希腊字母等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在绘图的轴标签中键入希腊字母和Angstrom符号.例如

I need to type Greek letters and the Angstrom symbol in labels of axes in a plot. So for example

fig.gca().set_xlabel("$wavelength\, (Angstrom)$")
fig.gca().set_ylabel("$lambda$")

除了我实际上希望将"Angstrom"和"lambda"替换为实际的符号.我应该怎么做?谢谢!

except that I actually want "Angstrom" and "lambda" replaced by actual symbols. How should I do this? Thanks!

推荐答案

不仅可以将原始字符串添加到matplotlib,还可以使用以下方法在matplotlibrc或本地指定字体:

Not only can you add raw strings to matplotlib but you can also specify the font in matplotlibrc or locally with:

from matplotlib import rc

rc('font', **{'family':'serif','serif':['Palatino']})
rc('text', usetex=True)

这将更改您的衬线乳胶字体.您也可以像这样指定Sans-serif Helvetica

This would change your serif latex font. You can also specify the sans-serif Helvetica like so

rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})

其他选项是cursivemonospace以及它们各自的字体名称.您的标签将是

Other options are cursive and monospace with their respective font names.Your label would then be

fig.gca().set_xlabel(r'wavelength $5000 \AA$')

如果字体不提供Angstrom符号,则可以尝试使用\mathring{A}

If the font doesn't supply an Angstrom symbol you can try using \mathring{A}

这篇关于在Python图中键入希腊字母等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 20:54