2016-11-23 4 views
0

私はPythonの初心者ですと以下のグラフを再現しようとしている: enter image description hereグラフ(ラテックス)

MWEは次のとおりです。

import numpy as np 
import matplotlib.mlab as mlab 
import matplotlib.pyplot as plt 
mu, sigma = 100, 15 
x = mu + sigma*np.random.randn(10000) 
# the histogram of the data 
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='green', 
          alpha=0.75) 
# add a 'best fit' line 
y = mlab.normpdf(bins, mu, sigma) 
l = plt.plot(bins, y, 'r--', linewidth=1) 
plt.xlabel('Smarts') 
plt.ylabel('Probability') 
plt.title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$') 
plt.axis([40, 160, 0, 0.03]) 
plt.grid(True) 
plt.show() 

と出力 ​​

です

しかし、ギリシャ文字は正しく売り切れていません。私はここで何か基本的なものを欠いているかもしれないに元のグラフを再現するように案内してくれたら大変感謝します。

編集

私はPython 2.4.1Python 3.5.2Ubuntu 16.10IDLEを使用します。

+0

使い方をPython 3.5.2からIPython/Anacondaまで(そしてアイドル状態でもテストされています)。私のプロンプトにあなたのコードをコピーするとき、それは完璧に正常に動作します。どこからあなたを走らせるのですか? – internetional

+0

@internetional:私の編集内容をご覧ください。何か考えてください。 – MYaseen208

+0

私があなただったら私はIPythonを試してみるでしょう。私はIDLEよりも安定している。悲しいことに私はあなたの問題を解決する方法についての手がかりはほとんどなく、アイデアも少なくなっています。 – internetional

答えて

1

あなたは大丈夫イマイチレンダリング場合、ラテックスフォントを変更するmatplotlibrcでフォントを指定することができます。

from matplotlib import rc 

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

または単に:

plt.title("Histogram of IQ: " r'$\mu = 100, \sigma$ =15') 

タイトルのサンプル出力: enter image description here

+0

あなたの答えは@アキレスです。 import matplotlib.pyplot as plt'の後に 'from matplotlib import rc'を使用しました。しかし、まだ同じ問題があります。何かご意見は。 – MYaseen208

+0

私は 'plt.title(r '$ \ mathrm {ヒストグラム\\ IQ:} \\ mu = 100、\\シグマ= 15 $')'を使用しています。 – MYaseen208

+0

いいえ、動作していません。 – MYaseen208

関連する問題