如何制作matplotlib下标和特殊字符?

时间:2012-06-18 15:40:50

标签: python matplotlib

我想使用matplotlib为我的绘图的轴标签制作下标。我有以下脚本快照:

import matplotlib.pylab as plt
plt.ylabel(r'$A^{2}$')

我有两个问题:

  1. 在情节中,下标“2”似乎占据整个单词长度而不是一半,这使得情节有点奇怪。如何使下标更小(尺寸和长度跨度)?

  2. 如何显示“埃”(长度单位为10 ^ -10m)而不是A?

  3. 谢谢!

2 个答案:

答案 0 :(得分:4)

  1. 您使用的是什么版本的matplotlib?在我的版本中,上标似乎很好(对我而言)。 我使用python 2.6.5和matplotlib 1.1.0

  2. 使用\ AA代表angstram - > plt.ylabel( “$ \ $ AA”)。 但圆圈有点小。

答案 1 :(得分:1)

如果您可以使用,请尝试使用TeX渲染文字。

from matplotlib import rc
rc('text', usetex=True)

#the rest of your plotting code here

这会使你的字体和文字看起来更好。

有关matplotlib的TeX渲染功能的更多详细信息,请查看此处:http://matplotlib.sourceforge.net/users/usetex.html