我正在编写一个小的 python 程序来进行频率分析,我想知道如何让所有的 bin 显示在 x 轴上而不是仅以 5 为增量显示。还有一种方法可以显示字符串x 轴上的值类似于“A”而不是数字?
代码:
print "Please specify the file to analyse."
FileContents = FileToIntArray()
# Count letter occurances in file
letterCounts = zeros(26).tolist()
for x in FileContents:
i = AlphaNum.index(x)
letterCounts[i] = letterCounts[i] + 1
# Plot histogram of counts
print "" # Newline
title("Absolute Frequencies")
xlabel("Letters A-B (Where A = 0 & Z = 25)")
ylabel("Letter Occurences")
hist(letterCounts, bins=AlphaNum)
show()
谢谢, 亚历克斯。
最佳答案
您可以使用 xticks .
xticks(arange(len(AlphaNum)),AlphaNum)
关于python - Pylab 直方图显示 x 轴上的所有 bin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5972328/