Sections
Sub-Sections
Last Change
Annotate
Revision Log
Download
Plain Text
Original Format
Metanav
Preferences
About Trac
Links
Slowchop Studios
Gerald Kaszuba
Advertisement

root/trunk/examples/labels.py

Revision 62, 2.3 kB (checked in by gak, 18 months ago)
  • Fixed line endings to UNIX
  • Fixed Hashbangs
  • Added GPL headers
  • Property svn:keywords set to Id Revision
Line 
1#!/usr/bin/env python
2"""
3Copyright Gerald Kaszuba 2008
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program.  If not, see <http://www.gnu.org/licenses/>.
17"""
18
19import os
20import sys
21import math
22import random
23
24ROOT = os.path.dirname(os.path.abspath(__file__))
25sys.path.insert(0, os.path.join(ROOT, '..'))
26
27from pygooglechart import SimpleLineChart
28from pygooglechart import Axis
29
30import settings
31import helper
32
33def cat_proximity():
34    """Cat proximity graph from http://xkcd.com/231/"""
35    chart = SimpleLineChart(int(settings.width * 1.5), settings.height)
36    chart.set_legend(['INTELLIGENCE', 'INSANITY OF STATEMENTS'])
37
38    # intelligence
39    data_index = chart.add_data([100. / y for y in xrange(1, 15)])
40
41    # insanity of statements
42    chart.add_data([100. - 100 / y for y in xrange(1, 15)])
43
44    # line colours
45    chart.set_colours(['208020', '202080'])
46
47    # "Near" and "Far" labels, they are placed automatically at either ends.
48    near_far_axis_index = chart.set_axis_labels(Axis.BOTTOM, ['FAR', 'NEAR'])
49
50    # "Human Proximity to cat" label. Aligned to the center.
51    index = chart.set_axis_labels(Axis.BOTTOM, ['HUMAN PROXIMITY TO CAT'])
52    chart.set_axis_style(index, '202020', font_size=10, alignment=0)
53    chart.set_axis_positions(index, [50])
54
55    chart.download('label-cat-proximity.png')
56
57def many_labels():
58    chart = SimpleLineChart(settings.width, settings.height)
59
60    for a in xrange(3):
61        for axis_type in (Axis.LEFT, Axis.RIGHT, Axis.BOTTOM):
62            index = chart.set_axis_range(axis_type, 0, random.random() * 100)
63            chart.set_axis_style(index, colour=helper.random_colour(), \
64                font_size=random.random() * 10 + 5)
65
66    chart.add_data(helper.random_data())
67    chart.download('label-many.png')
68
69def main():
70    cat_proximity()
71    many_labels()
72
73if __name__ == '__main__':
74    main()
Note: See TracBrowser for help on using the browser.