PostHeaderIcon Python Distribute Value Bar Chart

A bar chart can also be a good choice for plotting histograms of bucketed numeric values.
Let us see a short example. we have a score array.
# array[83,95,91,87,70,0,85,82,100,67,73,77,0]
the result of these array is below:
distribute value bar chart
the code is also simple:

# !/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Jerry'
from matplotlib import pyplot as cplt

# A Counter turns a sequence of values into
# a defaultdict(int)-like object mapping keys to counts.

from collections import Counter

scores = [83,95,91,87,70,0,85,82,100,67,73,77,0]

den = lambda g: g/10*10

hgram = Counter(den(score) for score in scores)[x-4 for x in hgram.keys()], hgram.values(), 8) 

cplt.axis([-5, 105, 0, 5])

cplt.xticks([10*i for i in range(11)])

cplt.ylabel("# of Students")
cplt.title("Exam On Class One")

Leave a Reply

Your email address will not be published. Required fields are marked *



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2010 - C++ Technology. All Rights Reserved.

Powered by Jerry | Free Space Provided by