Reputation: 21
I am currently attempting to create a histogram that charts the values from a dictionary I created. I have searched for similar questions on here but I am still confused on this block. Apologies if this is a repeat question.
The dictionary olf_kmer_hits currently look like this: {AAAAAAAAAAAA: -1.333}. I am interested in plotting each value for this dictionary. However, I am not seeing all my values: histogram output. I should have values from -2.5 to 2. One part of the code where I'm not sure is
The code is below.
for score in olf_kmer_hits.values():
k_m = np.histogram(score)
plt.hist(k_m)
plt.title('Histogram of {} 12aa K-mers'.format(len(olf_kmer_hits)))
plt.ylabel('Number of K-mers')
plt.xlabel('HOPS average score')
plt.axis([-1, 1, 0, 9.5])
plt.show() #there should be 85,984
Upvotes: 1
Views: 72
Reputation: 21
So I fixed my code and this is giving me the correct output image. Thank you @chrisz for the help.
score =[k_score for k_score in olf_kmer_hits.values()]
#np.histogram(score) #edit:1 np.histogram isn't being used
value, bins, patches = plt.hist(score)
plt.title('Histogram of {} 12aa K-mers'.format(len(olf_kmer_hits)))
plt.ylabel('Number of K-mers')
plt.xlabel('HOPS average score')
plt.axis([-4.5, 2.5, 0, 47000])
plt.show() #there should be 85,984
Upvotes: 1