histogram matplotlib,直方图文本

时间:2015-12-14 20:17:38

标签: python matplotlib histogram

使用python和matplotlib,我可以绘制直方图,我可以在直方图区域中放置文本,

import matplotlib.pyplot as plt
import numpy as np


a = np.array([10, 10, 10, 8, 9, 9, 7])

mean = np.mean(a)

fig = plt.figure(figsize=(14, 8))
ax = fig.add_subplot(111)

plt.hist(a, alpha=0.2)

ax.set_ylabel(u'Frequency')
ax.set_xlabel(u'Some data')
ax.xaxis.set_label_coords(0.8, -0.1)

ax.text(mean, 0, '$\mu$\n{}'.format(mean))

plt.show()

如何将文字放在轴下?

histogram http://f.cl.ly/items/001Z0C0c043q2g262b1F/Captura_de_pantalla_121415_051321_PM.jpg

1 个答案:

答案 0 :(得分:1)

使用y的负值:

ax.text(mean, -0.3, '$\mu$\n{}'.format(mean))