繁体   English   中英

Python 3.5.2中带有希腊字母(LaTeX)的图形

[英]Graph in Python 3.5.2 with Greek Letters (LaTeX)

我是Python新手,并尝试重现下图:

在此处输入图片说明

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 3.5.2中重现原始图形?

已编辑

我在Ubuntu 16.10上通过Python 2.4.1和IDLE使用了Python 3.5.2。

如果渲染不好,您可以在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')

标题的示例输出: 在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM