Python 直方图matplotlib,直方图外的文本

Python 直方图matplotlib,直方图外的文本,python,matplotlib,histogram,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_ylab

使用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()
如何将文本置于轴下


使用负值表示
y

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

您可以使用“\n”跳过行以将其删除。这可能暂时有效。