Bar chart in pylab from dictionary

I read about it. And I could not find a way to display the data for the histogram. The way I understand it:

The histogram has a name and a value for each bin.

This seems to be a fairly simple and intuitive way to look at it. I searched and found this question: python: creating a histogram from a dictionary

Which seemed to be long from what I ask.

I have the following dictionary:

d = {'CLOVER':4,'SPADE':6,'DIAMOND':7,'HEART':2} 

And I want to create a histogram with this dictionary. The numbers will increase. But the number of boxes will remain four.

I do it as a project. We do this from different implementations, and then check how random (pseudo-randomly technically) each implementation is. And then we need to submit a report. What we will build together.

please help me with the code. And also some examples.

the functions

 Python 2.7 Tkinter 8.5 Pylab 
+8
python matplotlib
source share
1 answer

I tried this and get a similar histogram:

 import pylab as pl import numpy as np d = {'CLOVER':4,'SPADE':6,'DIAMOND':7,'HEART':2} X = np.arange(len(d)) pl.bar(X, d.values(), align='center', width=0.5) pl.xticks(X, d.keys()) ymax = max(d.values()) + 1 pl.ylim(0, ymax) pl.show() 

This is not the same, but similar. If you want to change the color, width, etc. Just refer to http://matplotlib.org/api/pyplot_api.html . enter image description here

+16
source share

All Articles