Python 记录直方图中的计数值,而不是轴本身

Python 记录直方图中的计数值,而不是轴本身,python,matplotlib,histogram,Python,Matplotlib,Histogram,我举了这个例子来说明我正在尝试做什么: data = np.random.normal(loc=1000,scale=20,size=2000) plt.hist(np.log10(data),log=True) plt.xlabel('Log(data)') plt.ylabel('Count') plt.show() 执行这个命令后,我得到了一个很好的直方图,x轴上有Log(数据),y轴上有计数(y轴是对数比例的)。出于某种原因,我希望在y刻度上记录(计数),我的意思是不是记录轴,而是记录

我举了这个例子来说明我正在尝试做什么:

data = np.random.normal(loc=1000,scale=20,size=2000)
plt.hist(np.log10(data),log=True)
plt.xlabel('Log(data)')
plt.ylabel('Count')
plt.show()

执行这个命令后,我得到了一个很好的直方图,x轴上有Log(数据),y轴上有计数(y轴是对数比例的)。出于某种原因,我希望在y刻度上记录(计数),我的意思是不是记录轴,而是记录值本身。因此,就像日志(数据)与日志(计数)一样,轴本身也不应该被记录。谢谢你的帮助

我不确定是否可以用hist()函数本身来实现这一点,但可以用条形图轻松地重新创建它

import numpy as np
import matplotlib.pyplot as plt

data = np.random.normal(loc=1000,scale=20,size=2000)
n, bins, patches = plt.hist(np.log10(data),log=True)

# Extract the midpoints and widths of each bin.
bin_starts = bins[0:bins.size-1]
bin_widths = bins[1:bins.size] - bins[0:bins.size-1]

# Clear the histogram plot and replace it with a bar plot.
plt.clf()
plt.bar(bin_starts,np.log10(n),bin_widths)
plt.xlabel('Log(data)')
plt.ylabel('Log(Counts)')
plt.show()