root/trunk/examples/scatterchart.py

Revision 169, 1.7 kB (checked in by lgs, 3 years ago)

Big refactor about how the colors scheme are created and used. See #29

Line 
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
18import random
19import sys
20
21import cairo
22
23import pycha.scatter
24
25def scatterplotChart(output):
26    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 400, 200)
27
28
29    dataSet = (
30        ('points', [(i, random.random() * 100.0) for i in range(100)]),
31        )
32
33    options = {
34        'background': {
35            'color': '#eeeeff',
36            'lineColor': '#444444'
37        },
38        'colorScheme': {
39            'name': 'gradient',
40            'args': {
41                'initialColor': 'blue',
42            },
43        },
44        'legend': {
45            'hide': True,
46        },
47        'padding': {
48            'left': 55
49        }
50    }
51    chart = pycha.scatter.ScatterplotChart(surface, options)
52
53    chart.addDataset(dataSet)
54    chart.render()
55
56    surface.write_to_png(output)
57
58if __name__ == '__main__':
59    if len(sys.argv) > 1:
60        output = sys.argv[1]
61    else:
62        output = 'scatterchart.png'
63    scatterplotChart(output)
Note: See TracBrowser for help on using the browser.