Search code examples
pythondictionaryhistogramgraphing

How to graph a python frequency dictionary?


I am trying to graph a word frequency dict I have created, the dictionary structure is like:

OrderedDict([('abc', 367), ('abc', 312), ('abc', 286), ('abc', 57)])

However when running in Jupyer Notebook with the code shown below it is coming out poorly formatted.

Any suggestions? Many thanks in advance

a


Solution

  • I'd suggest using matplotlib.

    Using a histogram is the easiest way to do this, but plt.hist(a) requires a to be a list.

    If you're using a dictionary, you can use plt.bar():

    plt.bar(odict.keys(), odict.values(), width)