【问题标题】:Pylab Histogram show all bins on x axisPylab 直方图在 x 轴上显示所有 bin
【发布时间】: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


【解决方案1】:

您可以使用xticks

xticks(arange(len(AlphaNum)),AlphaNum)

【讨论】:

    猜你喜欢
    • 2010-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多