1# Copyright(c) 2007-2010 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 sys 19 20import cairo 21 22import pycha.bar 23 24 25def barChart(output, chartFactory): 26 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 800, 400) 27 28 # note that this dataset is composed by triplets, where the 29 # third item is the error 30 dataSet = ( 31 ('data 1', [(0, 30, 5), (1, 40, 7), (2, 25, 3), (3, 50, 10)]), 32 ) 33 34 options = { 35 'background': { 36 'chartColor': '#ffeeff', 37 'baseColor': '#ffffff', 38 'lineColor': '#444444', 39 }, 40 'legend': { 41 'hide': True, 42 }, 43 'title': 'Error bars' 44 } 45 chart = chartFactory(surface, options) 46 47 chart.addDataset(dataSet) 48 chart.render() 49 50 surface.write_to_png(output) 51 52if __name__ == '__main__': 53 if len(sys.argv) > 1: 54 output = sys.argv[1] 55 else: 56 output = 'errorbars.png' 57 barChart('v' + output, pycha.bar.VerticalBarChart) 58 barChart('h' + output, pycha.bar.HorizontalBarChart) 59