0

I am trying to write a letter recognition program and display some values on a histogram. But I cannot show the number of each letter and the number on the histogram. I am using matplotlib to create a histogram.

I was expecting that the histogram would show me the letters as x values and the numbers as y values. but it only shows the numbers as x values.


letters = pd.read_csv('C:/Users/Lenovo/Desktop/Yapay Zeka/odev1/letter_recognition.data')


dataframe = {
        "x" : letters['Letter'].value_counts().index,
        "y" : letters['Letter'].value_counts().values
}
son = pd.DataFrame(dataframe)
plt.hist(son)
plt.ylabel('numbers')
plt.xlabel('letters')
plt.show()



1 Answers1

0

Assuming you're storing your data in a dictionary called let_dict with the keys the letters and the values the count of the letters. You can plot your histogram with plt.bar(let_dict.keys(), let_dict.values()) (see this SO post for more examples on how to plot the histogram of a dictionary).

Here is the full code where I create a letter dictionary with random counts and I plot the histogram:

import matplotlib.pyplot as plt
import numpy as np
import string

let_dict={l:np.random.choice(20) for l in list(string.ascii_lowercase)}
plt.bar(let_dict.keys(),let_dict.values())
plt.show()

enter image description here

jylls
  • 4,395
  • 2
  • 10
  • 21