histogram matplotlib, 文本出直方图
histogram matplotlib, text out of 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()
如何将文本放在轴下方?
y
使用负值:
ax.text(mean, -0.3, '$\mu$\n{}'.format(mean))
使用 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))