python - Pylab 直方图显示 x 轴上的所有 bin

标签 python graph histogram matplotlib

我正在编写一个小的 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/

相关文章:

python - 如何将 Django 项目转换为我自己项目中的 Django 应用程序?

java - 比较java中的顶点对

julia - 获取从输入的每个元素到 Julia 中直方图的 bin 的映射

java - 无法修复 null 'key' 参数以生成要生成的图表

ios - Swift:图表填充线等

python - Pandas/Matplotlib 直方图问题 - x 轴刻度在子图和额外不需要的图表空间中消失。试过 tight_layout 和 subplots_adjust

numpy - numpy中对数对数直方图的线性回归

python - 从 settings.py 文件夹内的应用程序设置 AUTH_USER_MODEL

python - 如何在 Numba cuda 中对字符串数组执行内核函数?

python - 带有 Unicode 连接字符串的 pyodbc TypeError