~ubuntu-branches/ubuntu/lucid/pycha/lucid

« back to all changes in this revision

Viewing changes to docs/examples/barchart.py

  • Committer: Bazaar Package Importer
  • Author(s): Vincent Bernat
  • Date: 2009-03-18 20:27:10 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090318202710-dm6eicm7lxnjg3jp
Tags: 0.4.2-2
* Recompile with python-support from unstable. Closes: #520224.
* Bump Standards-Version to 3.8.1. No changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2007-2008 by Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
 
2
#
 
3
# This file is part of PyCha.
 
4
#
 
5
# PyCha is free software: you can redistribute it and/or modify
 
6
# it under the terms of the GNU Lesser General Public License as published by
 
7
# the Free Software Foundation, either version 3 of the License, or
 
8
# (at your option) any later version.
 
9
#
 
10
# PyCha is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU Lesser General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU Lesser General Public License
 
16
# along with PyCha.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
import sys
 
19
 
 
20
import cairo
 
21
 
 
22
import pycha.bar
 
23
 
 
24
import precip
 
25
 
 
26
def barChart(output, chartFactory):
 
27
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 500, 300)
 
28
 
 
29
    dataSet = (
 
30
        ('Tainan', [(i, l[1]) for i, l in enumerate(precip.Tainan)]),
 
31
        ('Paris', [(i, l[1]) for i, l in enumerate(precip.Paris)]),
 
32
        )
 
33
 
 
34
    options = {
 
35
        'axis': {
 
36
            'x': {
 
37
                'ticks': [dict(v=i, label=l[0]) for i, l in enumerate(precip.Tainan)],
 
38
                'label': 'Month',
 
39
                'rotate': 25,
 
40
            },
 
41
            'y': {
 
42
                'tickCount': 4,
 
43
                'rotate': 25,
 
44
                'label': 'Precipitation (mm)'
 
45
            }
 
46
        },
 
47
        'background': {
 
48
            'chartColor': '#d8e7ec',
 
49
            'baseColor': '#efebe7',
 
50
            'lineColor': '#444444'
 
51
        },
 
52
        'colorScheme': '#6eafc1',
 
53
        'legend': {
 
54
            'hide': False,
 
55
            'position': {'top': 5, 'left': 5},
 
56
        },
 
57
        'padding': {
 
58
            'left': 135,
 
59
            'bottom': 55,
 
60
        },
 
61
        'title': 'Monthly Precipitation'
 
62
    }
 
63
    chart = chartFactory(surface, options)
 
64
 
 
65
    chart.addDataset(dataSet)
 
66
    chart.render()
 
67
 
 
68
    surface.write_to_png(output)
 
69
 
 
70
if __name__ == '__main__':
 
71
    if len(sys.argv) > 1:
 
72
        output = sys.argv[1]
 
73
    else:
 
74
        output = 'barchart.png'
 
75
    barChart('v' + output, pycha.bar.VerticalBarChart)
 
76
    barChart('h' + output, pycha.bar.HorizontalBarChart)