Sections
Timeline
View Tickets
New Ticket
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 14, 1.7 kB (checked in by gak, 11 months ago)

removed debugging from an example

  • Property svn:keywords set to Id Revision
Line 
1#!/usr/bin/env python
2
3import os
4import sys
5import math
6import random
7
8ROOT = os.path.dirname(os.path.abspath(__file__))
9sys.path.insert(0, os.path.join(ROOT, '..'))
10
11from pygooglechart import SimpleLineChart
12from pygooglechart import Axis
13
14import settings
15import helper
16
17def cat_proximity():
18    """Cat proximity graph from http://xkcd.com/231/"""
19    chart = SimpleLineChart(int(settings.width * 1.5), settings.height)
20    chart.set_legend(['INTELLIGENCE', 'INSANITY OF STATEMENTS'])
21
22    # intelligence
23    data_index = chart.add_data([100. / y for y in xrange(1, 15)])
24
25    # insanity of statements
26    chart.add_data([100. - 100 / y for y in xrange(1, 15)])
27
28    # line colours
29    chart.set_colours(['208020', '202080'])
30
31    # "Near" and "Far" labels, they are placed automatically at either ends.
32    near_far_axis_index = chart.set_axis_labels(Axis.BOTTOM, ['FAR', 'NEAR'])
33
34    # "Human Proximity to cat" label. Aligned to the center.
35    index = chart.set_axis_labels(Axis.BOTTOM, ['HUMAN PROXIMITY TO CAT'])
36    chart.set_axis_style(index, '202020', font_size=10, alignment=0)
37    chart.set_axis_positions(index, [50])
38
39    chart.download('label-cat-proximity.png')
40
41def many_labels():
42    chart = SimpleLineChart(settings.width, settings.height)
43
44    for a in xrange(3):
45        for axis_type in (Axis.LEFT, Axis.RIGHT, Axis.BOTTOM):
46            index = chart.set_axis_range(axis_type, 0, random.random() * 100)
47            chart.set_axis_style(index, colour=helper.random_colour(), \
48                font_size=random.random() * 10 + 5)
49
50    chart.add_data(helper.random_data())
51    chart.download('label-many.png')
52
53def main():
54    cat_proximity()
55    many_labels()
56
57if __name__ == '__main__':
58    main()
Note: See TracBrowser for help on using the browser.