Alex Hope O'Connor
Alex Hope O'Connor

Reputation: 9714

Pylab Histogram show all bins on x axis

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.

Upvotes: 2

Views: 6265

Answers (1)

GWW
GWW

Reputation: 44161

You can use xticks.

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

Upvotes: 1

Related Questions