have a dictionary

dictionary = {5 : 31, 0 : 29, 12 : 29, 7 : 27, 32 : 26, 13 : 25, 4 : 24, 3 : 23, 16 : 23, 17 : 22, 31 : 22, 6 : 21, 9 : 21, 10 : 21, 2 : 20, 20 : 19, 22 : 19, 23 : 17, 1 : 17, 21 : 17, 34 : 17, 24 : 17, 15 : 17, 29 : 16} 

so you can build a regular histogram on these values ​​(value - how many times this value occurs)

 plt.bar(list(dictionary.keys()), dictionary.values(), 1, color='g') 

How to build a histogram of the distribution of values? (approximate probability distribution density) python

    1 answer 1

    Use Pandas :

     import pandas as pd import matplotlib.pyplot as plt import matplotlib matplotlib.style.use('ggplot') s = pd.Series(dictionary) s.plot.kde() 

    enter image description here

    in the form of a histogram:

     s.plot.hist(alpha=0.6) 

    enter image description here

    save schedule:

     plt.savefig(r'/path/to/figure.png') 
    • @jfs, I didn’t try without pyplot - I’ll try when I get to the computer ... Usually plt.show () or plt.savefig () is added to the script at the end at Feb.