2017-05-03 81 views
0

因为这是我在SO上的第一篇文章,所以我想说“大家好”。错误的特殊符号matplotlib

我有一个问题,使用matplotlib。当我写数学表达式时,所有的特殊符号如r'$\bigodot$'r'$\sigma$'我完全收集不同的符号。这是正确的,从我的代码更具体的例子:

for i in radi: 
    plt.plot(temp,Lum(i,temp),'--b') 
    plt.text(temp[0],Lum(i,temp[0]),'R = '+str(i)+r'$R_\odot$') 

和这里就是我收到的情节:

enter image description here

我用在Ubuntu 16.10的Python 2.7。如果您对我能做什么有任何想法,我将不胜感激。我朋友电脑上的相同代码工作正常。

+0

由于代码几乎可以在每个系统上产生预期的结果,所以我想您应该更深入了解什么使您的系统与众不同。你使用的是哪个版本的matplotlib,在哪个后端,你使用哪个fontset等等? – ImportanceOfBeingErnest

+0

'Python 2.7.12+(default,2016年9月17日,12:08:02) [GCC 6.2.0 20160914] on linux2 输入“help”,“copyright”,“credits”或“license”以获取更多信息。 >>> import matplotlib >>> matplotlib.get_backend() u'TkAgg'' 关于字体...我没有定制任何东西。我尝试过使用:'plt.rc('font',family ='STIXGeneral')',因为它是somwhere的建议,但它没有帮助。 – Janko

+0

你有没有尝试过使用不同的字体集? 'plt.rcParams [“mathtext.fontset”] =“dejavusans”与'dejavusans'(默认),'dejavuserif','cm','stix','stixsans'? – ImportanceOfBeingErnest

回答

0

Matplotlib提供了在渲染MathText时使用的不同字体集。很可能您的matplotlib安装中的设置不适合,并且您需要使用不同的字体集。

plt.rcParams["mathtext.fontset"] = "dejavusans" 

有效fontsets应'dejavusans'(在matplotlib 2.0默认值),'dejavuserif''cm''stix''stixsans'