Pylab 直方图显示 x 轴上的所有 bin
我正在编写一个小型 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()
谢谢, 亚历克斯.
Im writing a small python program to do a frequency analysis, and I was wondering how you might get all the bins to show on the x axis rather then just in increments of 5. Also is there a way you can display a string value like "A" on the x axis instead of a number?
Code:
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()
Thanks,
Alex.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 xticks。
You can use xticks.