使用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
答案 0 :(得分:1)
使用y
的负值:
ax.text(mean, -0.3, '$\mu$\n{}'.format(mean))