【发布时间】:2016-07-07 12:03:04
【问题描述】:
在 MATLAB 中,如果您在轴标签中键入“\alpha”,它将呈现“纯文本”希腊字符 alpha,而无需 Latex。我希望对 Matplotlib 的 Pyplot 做同样的事情。
按照How to use unicode symbols in matplotlib?,我尝试了以下方法:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
if __name__ == "__main__":
plt.figure()
prop = FontProperties()
prop.set_file('STIXGeneral.ttf')
plt.xlabel(u"\u2736", fontproperties=prop)
plt.show()
x = np.linspace(-1,1,21)
plt.figure()
plt.plot(x,x)
plt.xlabel(u"\u03b1") # Attempt at creating an axis label with a Unicode alpha
# plt.xlabel(r'$\alpha$') # I'm aware that Latex is possible
plt.show()
但是,我收到一条以
结尾的错误消息IOError: [Errno 2] No such file or directory: 'STIXGeneral.ttf'
如果我省略第 3-10 行,我不会收到错误消息,但绘图显示的是正方形而不是希腊字母 alpha:
可以用 Matplotlib 做到这一点吗? (我知道显示 Latex 的可能性,但更喜欢“纯文本”选项)。
【问题讨论】:
标签: python matplotlib unicode