PostHeaderIcon Python Bar Charts

A bar chart is a good choice when you want to show how some quantity varies among some discrete set of items.

For instance, Figure below shows how many Movies Awards were won by each of stars.
Python Bar Charts
# bars are by default width 0.8, so we’ll add 0.1 to the left coordinates, so that each bar is centered
# then we set plot bars with left x-coordinates [xs], heights [num_ads]
# last we set label x-axis with star names at bar center
here’s the code:

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

stars = ["TingFeng Xie", "DeHua Liu", "ChaoWei Liang", "QingYun Liu",
          "JiaHui Liang", "JiaHui Zhang"]
num_ads = [5, 11, 13, 8, 10, 7]

xs = [i+0.1 for i,_ in enumerate(stars)], num_ads)

cplt.ylabel("# of Movie Awards")

cplt.title("Super Stars")

cplt.xticks([i+0.5 for i,_ in enumerate(stars)], stars)

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