~alf-rodrigo/cairoplot/trunk

« back to all changes in this revision

Viewing changes to trunk/tests.py

  • Committer: Rodrigo Moreira Araújo
  • Date: 2009-01-30 22:27:22 UTC
  • Revision ID: alf.rodrigo@gmail.com-20090130222722-0300an3ebypgq4a0
* CairoPlot.py: -Class structure was refactored as it was noted that
                                 the new ScatterPlot was able to render DotLine and 
                                 FunctionPlots;
                                -Following the refactoring, the bounds associated with
                                 a FunctionPlot chart (x_bounds) now define a closed
                                 interval, which means the last value is also taken
                                 taken into account;
                                -Error bars support was added to the ScatterPlot;
                                -All h_* and v_* parameters have been changed to x_*
                                 and y_*.
* tests.py:     -FunctionPlot tests were changed to fit the new bounds;
                                -All tests were changed to reflect the h_* and v_* to 
                                 x_* and y_* parameter change.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import CairoPlot
2
2
import cairo
3
3
import math
 
4
import random
4
5
 
5
6
test_bar_plot = 0
6
7
test_scatter_plot = 1
28
29
 
29
30
    #Using no labels, horizontal and vertical labels
30
31
    data = [[3,4], [4,8], [5,3], [9,1]]
31
 
    v_labels = [ "line1", "line2", "line3", "line4", "line5", "line6" ]
32
 
    h_labels = [ "group1", "group2", "group3", "group4" ]
 
32
    y_labels = [ "line1", "line2", "line3", "line4", "line5", "line6" ]
 
33
    x_labels = [ "group1", "group2", "group3", "group4" ]
33
34
    CairoPlot.bar_plot ( 'bar_5_no_labels', data, 600, 200, border = 20, grid = True )
34
 
    CairoPlot.bar_plot ( 'bar_6_h_labels', data, 600, 200, border = 20, grid = True, h_labels = h_labels )
35
 
    CairoPlot.bar_plot ( 'bar_7_v_labels', data, 600, 200, border = 20, grid = True, v_labels = v_labels )
36
 
    CairoPlot.bar_plot ( 'bar_8_hv_labels', data, 600, 200, border = 20, grid = True, h_labels = h_labels, v_labels = v_labels )
 
35
    CairoPlot.bar_plot ( 'bar_6_x_labels', data, 600, 200, border = 20, grid = True, x_labels = x_labels )
 
36
    CairoPlot.bar_plot ( 'bar_7_y_labels', data, 600, 200, border = 20, grid = True, y_labels = y_labels )
 
37
    CairoPlot.bar_plot ( 'bar_8_hy_labels', data, 600, 200, border = 20, grid = True, x_labels = x_labels, y_labels = y_labels )
37
38
 
38
39
if test_donut_plot :
39
40
    #Define a new backgrond
51
52
    #Default plot
52
53
    data = [ 0, 1, 3.5, 8.5, 9, 0, 10, 10, 2, 1 ]
53
54
    CairoPlot.dot_line_plot( "dot_line_1_default", data, 400, 300, border = 50, axis = True, grid = True,
54
 
                             h_title = "x axis", v_title = "y axis" )
 
55
                             x_title = "x axis", y_title = "y axis" )
55
56
 
56
57
    #Labels
57
58
    data = { "john" : [-5, -2, 0, 1, 3], "mary" : [0, 0, 3, 5, 2], "philip" : [-2, -3, -4, 2, 1] }
58
 
    h_labels = [ "jan/2008", "feb/2008", "mar/2008", "apr/2008", "may/2008" ]
59
 
    v_labels = [ "very low", "low", "medium", "high", "very high" ]
60
 
    CairoPlot.dot_line_plot( "dot_line_2_dictionary_labels", data, 400, 300, h_labels = h_labels, 
61
 
                             v_labels = v_labels, axis = True, grid = True,
62
 
                             h_title = "x axis", v_title = "y axis", series_legend=True )
 
59
    x_labels = [ "jan/2008", "feb/2008", "mar/2008", "apr/2008", "may/2008" ]
 
60
    y_labels = [ "very low", "low", "medium", "high", "very high" ]
 
61
    CairoPlot.dot_line_plot( "dot_line_2_dictionary_labels", data, 400, 300, x_labels = x_labels, 
 
62
                             y_labels = y_labels, axis = True, grid = True,
 
63
                             x_title = "x axis", y_title = "y axis", series_legend=True )
63
64
    
64
65
    #Series legend
65
66
    data = { "john" : [10, 10, 10, 10, 30], "mary" : [0, 0, 3, 5, 15], "philip" : [13, 32, 11, 25, 2] }
66
 
    h_labels = [ "jan/2008", "feb/2008", "mar/2008", "apr/2008", "may/2008" ]
67
 
    CairoPlot.dot_line_plot( 'dot_line_3_series_legend', data, 400, 300, h_labels = h_labels, 
 
67
    x_labels = [ "jan/2008", "feb/2008", "mar/2008", "apr/2008", "may/2008" ]
 
68
    CairoPlot.dot_line_plot( 'dot_line_3_series_legend', data, 400, 300, x_labels = x_labels, 
68
69
                             axis = True, grid = True, series_legend = True )
69
70
 
70
71
if test_function_plot :
71
72
    #Default Plot
72
73
    data = lambda x : x**2
73
 
    CairoPlot.function_plot( 'function_1_default', data, 400, 300, grid = True, h_bounds=(-10,10), step = 0.1 )
 
74
    CairoPlot.function_plot( 'function_1_default', data, 400, 300, grid = True, x_bounds=(-10,10), step = 0.1 )
74
75
    
75
76
    #Discrete Plot
76
77
    data = lambda x : math.sin(0.1*x)*math.cos(x)
77
 
    CairoPlot.function_plot( 'function_2_discrete', data, 800, 300, discrete = True, dots = True, grid = True, h_bounds=(0,80), 
78
 
                             h_title = "t (s)", v_title = "sin(0.1*x)*cos(x)", step = 0.9)
 
78
    CairoPlot.function_plot( 'function_2_discrete', data, 800, 300, discrete = True, dots = True, grid = True, x_bounds=(0,80), 
 
79
                             x_title = "t (s)", y_title = "sin(0.1*x)*cos(x)")
79
80
 
80
81
    #Labels test
81
 
    data = lambda x : [1,2,3,4][x]
82
 
    h_labels = [ "4", "3", "2", "1" ]
83
 
    CairoPlot.function_plot( 'function_3_labels', data, 400, 300, discrete = True, dots = True, grid = True, h_labels = h_labels, h_bounds=(0,4), step = 1 )
 
82
    data = lambda x : [1,2,3,4,5][x]
 
83
    x_labels = [ "4", "3", "2", "1", "0" ]
 
84
    CairoPlot.function_plot( 'function_3_labels', data, 400, 300, discrete = True, dots = True, grid = True, x_labels = x_labels, x_bounds=(0,4), step = 1 )
84
85
    
85
86
    #Multiple functions
86
87
    data = [ lambda x : 1, lambda y : y**2, lambda z : -z**2 ]
90
91
if test_gantt_chart :
91
92
    #Default Plot
92
93
    pieces = [ (0.5,5.5) , [(0,4),(6,8)] , (5.5,7) , (7,9)]
93
 
    h_labels = [ 'teste01', 'teste02', 'teste03', 'teste04']
94
 
    v_labels = [ '0001', '0002', '0003', '0004', '0005', '0006', '0007', '0008', '0009', '0010' ]
 
94
    x_labels = [ 'teste01', 'teste02', 'teste03', 'teste04']
 
95
    y_labels = [ '0001', '0002', '0003', '0004', '0005', '0006', '0007', '0008', '0009', '0010' ]
95
96
    colors = [ (1.0, 0.0, 0.0), (1.0, 0.7, 0.0), (1.0, 1.0, 0.0), (0.0, 1.0, 0.0) ]
96
 
    CairoPlot.gantt_chart('gantt_1_default', pieces, 500, 350, h_labels, v_labels, colors)
 
97
    CairoPlot.gantt_chart('gantt_1_default', pieces, 500, 350, x_labels, y_labels, colors)
97
98
 
98
99
 
99
100
if test_pie_plot :
109
110
    CairoPlot.pie_plot( "pie_3_background", data, 600, 400, background = background, gradient = True, shadow = True )
110
111
 
111
112
if test_scatter_plot:
112
 
    #TODO: Correct comments
113
113
    #Default data
114
114
    data = [ (-2,10), (0,0), (0,15), (1,5), (2,0), (3,-10), (3,5) ]
115
 
    CairoPlot.scatter_plot ( 'scatter_1_default', data, 500, 500, border = 20, axis = True, grid = True )
116
 
    
117
 
    #Two Default data
118
 
    data = [ [ (0,0), (-2,10), (0,15), (1,5), (2,0), (3,-10), (3,5) ],
119
 
             [ (0,2), (-2,12), (0,17), (1,7), (2,2), (3,-8),  (3,7) ]  ]
120
 
    CairoPlot.scatter_plot ( 'scatter_2_default', data, 500, 500, border = 20, axis = True, grid = True )
121
 
    
122
 
    #Dictionary of Default data
123
 
    data = { 'data1' : [ (0,0), (0,10), (0,15), (1,5), (2,0), (3,-10), (3,5) ],
124
 
             'data2' : [ (2,2), (2,12), (2,17), (3,7), (4,2), (5,-8),  (5,7) ]  }
125
 
    CairoPlot.scatter_plot ( 'scatter_3_default', data, 500, 500, border = 20, axis = True, grid = True )
126
 
    
127
 
    #Two lists data
128
 
    data = [ [0, 0, 0, 1, 2, 3, 3], [0, 10, 15, 5, 0, -10, 5] ]
129
 
    CairoPlot.scatter_plot ( 'scatter_4_two_lists', data, 500, 500, border = 20, axis = True, discrete = True, dots = True, grid = True )
130
 
    
131
 
    #Two groups of two lists data
132
 
    data = [ [ [0, 0, 0, 1, 2, 3, 3], [0, 10, 15, 5, 0, -10, 5] ],
133
 
             [ [2, 2, 2, 3, 4, 5, 5], [2, 12, 17, 7, 2, -8, 7] ]  ]
134
 
    CairoPlot.scatter_plot ( 'scatter_5_two_lists', data, 500, 500, border = 20, axis = True, discrete = True, dots = True, grid = True )
135
 
    
136
 
    #Dictionary
137
 
    data = { 'data1' : [ [0, 0, 0, 1, 2, 3, 3], [0, 10, 15, 5, 0, -10, 5] ],
138
 
             'data2' : [ [2, 2, 2, 3, 4, 5, 5], [2, 12, 17, 7, 2, -8, 7] ]  }
139
 
    CairoPlot.scatter_plot ( 'scatter_6_two_lists', data, 500, 500, border = 20, axis = True, discrete = True, dots = True, grid = True )
 
115
    CairoPlot.scatter_plot ( 'cross_1_default', data = data, width = 500, height = 500, border = 20, axis = True, grid = True )
140
116
    
141
117
    data = [(-1, -16, 12), (-12, 17, 11), (-4, 6, 5), (4, -20, 12), (13, -3, 21), (7, 14, 20), (-11, -2, 18), (19, 7, 18), (-10, -19, 15),
142
118
            (-17, -2, 6), (-9, 4, 10), (14, 11, 16), (13, -11, 18), (20, 20, 16), (7, -8, 15), (-16, 17, 16), (16, 9, 9), (-3, -13, 25),
144
120
            (17, -15, 25), (-2, -8, 5), (5, 20, 20), (18, 20, 23), (-20, -16, 17), (-19, -2, 9), (-11, 19, 18), (17, 16, 12), (-5, -20, 15),
145
121
            (-20, -13, 10), (-3, 5, 20), (-1, 13, 17), (-11, -9, 11)]
146
122
    colors = [ (0,0,0,0.25), (1,0,0,0.75) ]
147
 
    CairoPlot.scatter_plot ( 'scatter_7_real_data', data, 500, 500, border = 20, axis = True, discrete = True, dots = True, 
148
 
                             grid = True, h_title = "x axis", v_title = "y axis", circle_colors = colors, radius = 2 )
149
 
    
 
123
    CairoPlot.scatter_plot ( 'cross_2_variable_radius', data = data, width = 500, height = 500, border = 20, 
 
124
                             axis = True, discrete = True, dots = 2, grid = True, 
 
125
                             x_title = "x axis", y_title = "y axis", circle_colors = colors )
 
126
    
 
127
    #Scatter x DotLine
 
128
    t = [x*0.1 for x in range(0,40)]
 
129
    f = [math.exp(x) for x in t]
 
130
    g = [10*math.cos(x) for x in t]
 
131
    erx = [0.1*random.random() for x in t]
 
132
    ery = [5*random.random() for x in t]
 
133
    data = {"exp" : [t,f], "cos" : [t,g]}
 
134
    series_colors = [ (1,0,0), (0,0,0) ]
 
135
    CairoPlot.scatter_plot ( 'cross_r_exponential', data = data, errorx = [erx,erx], errory = [ery,ery], width = 800, height = 600, border = 20, 
 
136
                             axis = True, discrete = False, dots = 5, grid = True, 
 
137
                             x_title = "t", y_title = "f(t) g(t)", series_legend=True, series_colors = series_colors )
 
138
    
 
139
    
 
140
    
 
 
b'\\ No newline at end of file'