3

I am trying to take a list of chars:

['a','a','b','c','c']

and generate a plot with x-axis as the char and the y axis as how many there are in that list.

Alec
  • 8,529
  • 8
  • 37
  • 63
CuriousOne
  • 49
  • 1
  • 2

2 Answers2

6

Use pandas and count the occurrences of the letters, then make a bar chart:

from collections import Counter
import pandas

data = ['a','a','b','c','c']
count = Counter(data)
df = pandas.DataFrame.from_dict(count, orient='index')
df.plot(kind='bar')
Alec
  • 8,529
  • 8
  • 37
  • 63
6

You can use pandas:

import pandas as pd
l = ['a','a','b','c','c']
df = pd.DataFrame({'freq': l})
df.groupby('freq', as_index=False).size().plot(kind='bar')
plt.show()

pandas is a large library, which does a lot of stuff with data, as well as plotting (it's using it from matplotlib though, so you see plt.show (matplotlib.pyplot.show()), and here you see an example of how you can use it.

U13-Forward
  • 69,221
  • 14
  • 89
  • 114