【发布时间】:2011-08-23 18:14:41
【问题描述】:
我正在编写一个小型 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()
谢谢, 亚历克斯。
【问题讨论】:
-
当你说 all bins to show 你是指所有的刻度标签吗?
-
是的,就是我想要的沿 x 轴的值。
标签: python graph histogram matplotlib