~mrooney/cairoplot/label-formatters

« back to all changes in this revision

Viewing changes to trunk/tests.py

  • Committer: Rodrigo Moreira Araujo
  • Date: 2009-03-08 20:28:42 UTC
  • Revision ID: rodrigo@scrooge-20090308202842-b2496nkb4ts4ru5m
CairoPlot.py: 
 - Code revision and refactoring;
 - The BarPlot class is now a base class on top of which the classes HorizontalBarPlot and VerticalBarPlot are built
 - Color themes are now available;
 - PiePlot and DonutPlot data is now ordered;
 - Horizontal label collision problem was solved for BarPlots;
 - Axis titles are now allowed for ScatterPlot, DotLinePlot and FunctionPlot classes.

tests.py:
 - Theme tests were added;
 - BarPlot tests were changed into HorizontalBarPlot and VerticalBarPlot tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import cairo
2
2
import math
3
3
import random
 
4
 
4
5
import cairoplot
5
6
 
6
 
test_bar_plot = 1
 
7
test_vertical_bar_plot = 1
 
8
test_horizontal_bar_plot = 1
7
9
test_scatter_plot = 1
8
10
test_donut_plot = 1
9
11
test_dot_line_plot = 1
12
14
test_pie_plot = 1
13
15
test_themes = 1
14
16
 
15
 
if test_bar_plot:
 
17
if test_vertical_bar_plot:
16
18
    #Passing a dictionary
17
19
    data = { 'teste00' : [27], 'teste01' : [10], 'teste02' : [18], 'teste03' : [5], 'teste04' : [1], 'teste05' : [22] }
18
 
    cairoplot.bar_plot ( 'bar_0_dictionary', data, 400, 300, border = 20, grid = True, rounded_corners = True )
 
20
    cairoplot.vertical_bar_plot ( 'vbar_0_dictionary', data, 400, 300, border = 20, grid = True, rounded_corners = True )
19
21
 
20
22
    #Using default, rounded corners and 3D visualization
21
23
    data = [ [0, 3, 11], [8, 9, 21], [13, 10, 9], [2, 30, 8] ]
22
24
    colors = [ (1,0.2,0), (1,0.7,0), (1,1,0) ]
23
 
    cairoplot.bar_plot ( 'bar_1_default', data, 400, 300, border = 20, grid = True, rounded_corners = False, colors = "yellow_orange_red" )
24
 
    cairoplot.bar_plot ( 'bar_2_rounded', data, 400, 300, border = 20, grid = True, rounded_corners = True, colors = colors )
25
 
    cairoplot.bar_plot ( 'bar_3_3D', data, 400, 300, border = 20, grid = True, three_dimension = True, colors = colors )
 
25
    cairoplot.vertical_bar_plot ( 'vbar_1_default', data, 400, 300, border = 20, grid = True, rounded_corners = False, colors = "yellow_orange_red" )
 
26
    cairoplot.vertical_bar_plot ( 'vbar_2_rounded', data, 400, 300, border = 20, grid = True, rounded_corners = True, colors = colors )
 
27
    cairoplot.vertical_bar_plot ( 'vbar_3_3D', data, 400, 300, border = 20, grid = True, three_dimension = True, colors = colors )
26
28
 
27
29
    #Mixing groups and columns
28
30
    data = [ [1], [2], [3,4], [4], [5], [6], [7], [8], [9], [10] ]
29
 
    cairoplot.bar_plot ( 'bar_4_group', data, 400, 300, border = 20, grid = True )
 
31
    cairoplot.vertical_bar_plot ( 'vbar_4_group', data, 400, 300, border = 20, grid = True )
30
32
 
31
33
    #Using no labels, horizontal and vertical labels
32
34
    data = [[3,4], [4,8], [5,3], [9,1]]
33
35
    y_labels = [ "line1", "line2", "line3", "line4", "line5", "line6" ]
34
36
    x_labels = [ "group1", "group2", "group3", "group4" ]
35
 
    cairoplot.bar_plot ( 'bar_5_no_labels', data, 600, 200, border = 20, grid = True )
36
 
    cairoplot.bar_plot ( 'bar_6_x_labels', data, 600, 200, border = 20, grid = True, x_labels = x_labels )
37
 
    cairoplot.bar_plot ( 'bar_7_y_labels', data, 600, 200, border = 20, grid = True, y_labels = y_labels )
38
 
    cairoplot.bar_plot ( 'bar_8_hy_labels', data, 600, 200, border = 20, grid = True, x_labels = x_labels, y_labels = y_labels )
 
37
    cairoplot.vertical_bar_plot ( 'vbar_5_no_labels', data, 600, 200, border = 20, grid = True )
 
38
    cairoplot.vertical_bar_plot ( 'vbar_6_x_labels', data, 600, 200, border = 20, grid = True, x_labels = x_labels )
 
39
    cairoplot.vertical_bar_plot ( 'vbar_7_y_labels', data, 600, 200, border = 20, grid = True, y_labels = y_labels )
 
40
    cairoplot.vertical_bar_plot ( 'vbar_8_hy_labels', data, 600, 200, border = 20, grid = True, x_labels = x_labels, y_labels = y_labels )
 
41
    
 
42
    #Large data set
 
43
    data = [[10*random.random()] for x in range(50)]
 
44
    x_labels = ["large label name oh my god it's big" for x in data]
 
45
    cairoplot.vertical_bar_plot ( 'vbar_9_large', data, 1000, 800, border = 20, grid = True, rounded_corners = True, x_labels = x_labels )
 
46
 
 
47
if test_horizontal_bar_plot:
 
48
    #Passing a dictionary
 
49
    data = { 'teste00' : [27], 'teste01' : [10], 'teste02' : [18], 'teste03' : [5], 'teste04' : [1], 'teste05' : [22] }
 
50
    cairoplot.horizontal_bar_plot ( 'hbar_0_dictionary', data, 400, 300, border = 20, grid = True, rounded_corners = True )
 
51
 
 
52
    #Using default, rounded corners and 3D visualization
 
53
    data = [ [0, 3, 11], [8, 9, 21], [13, 10, 9], [2, 30, 8] ]
 
54
    colors = [ (1,0.2,0), (1,0.7,0), (1,1,0) ]
 
55
    cairoplot.horizontal_bar_plot ( 'hbar_1_default', data, 400, 300, border = 20, grid = True, rounded_corners = False, colors = "yellow_orange_red" )
 
56
    cairoplot.horizontal_bar_plot ( 'hbar_2_rounded', data, 400, 300, border = 20, grid = True, rounded_corners = True, colors = colors )
 
57
 
 
58
    #Mixing groups and columns
 
59
    data = [ [1], [2], [3,4], [4], [5], [6], [7], [8], [9], [10] ]
 
60
    cairoplot.horizontal_bar_plot ( 'hbar_4_group', data, 400, 300, border = 20, grid = True )
 
61
 
 
62
    #Using no labels, horizontal and vertical labels
 
63
    data = [[3,4], [4,8], [5,3], [9,1]]
 
64
    x_labels = [ "line1", "line2", "line3", "line4", "line5", "line6" ]
 
65
    y_labels = [ "group1", "group2", "group3", "group4" ]
 
66
    cairoplot.horizontal_bar_plot ( 'hbar_5_no_labels', data, 600, 200, border = 20, grid = True )
 
67
    cairoplot.horizontal_bar_plot ( 'hbar_6_x_labels', data, 600, 200, border = 20, grid = True, x_labels = x_labels )
 
68
    cairoplot.horizontal_bar_plot ( 'hbar_7_y_labels', data, 600, 200, border = 20, grid = True, y_labels = y_labels )
 
69
    cairoplot.horizontal_bar_plot ( 'hbar_8_hy_labels', data, 600, 200, border = 20, grid = True, x_labels = x_labels, y_labels = y_labels )
 
70
    
 
71
    #Large data set
 
72
    data = [[10*random.random()] for x in range(50)]
 
73
    x_labels = ["large label name oh my god it's big" for x in data]
 
74
    cairoplot.horizontal_bar_plot ( 'hbar_9_large', data, 1000, 800, border = 20, grid = True, rounded_corners = True, x_labels = x_labels )
 
75
 
 
76
 
39
77
 
40
78
if test_donut_plot :
41
79
    #Define a new backgrond
89
127
    colors = [ (1.0, 0.0, 0.0 ), ( 0.0, 1.0, 0.0 ), ( 0.0, 0.0, 1.0 ) ]
90
128
    cairoplot.function_plot( 'function_4_multi_functions', data, 400, 300, grid = True, series_colors = colors, step = 0.1 )
91
129
 
 
130
    #Gaussian
 
131
    a = 1
 
132
    b = 0
 
133
    c = 1.5
 
134
    gaussian = lambda x : a*math.exp(-(x-b)*(x-b)/(2*c*c))
 
135
    cairoplot.function_plot( 'function_5_gaussian', data, 400, 300, grid = True, x_bounds = (-10,10), step = 0.1 )
 
136
 
92
137
if test_gantt_chart :
93
138
    #Default Plot
94
139
    pieces = [ (0.5,5.5) , [(0,4),(6,8)] , (5.5,7) , (7,9)]
113
158
if test_scatter_plot:
114
159
    #Default data
115
160
    data = [ (-2,10), (0,0), (0,15), (1,5), (2,0), (3,-10), (3,5) ]
116
 
    cairoplot.scatter_plot ( 'cross_1_default', data = data, width = 500, height = 500, border = 20, axis = True, grid = True )
 
161
    cairoplot.scatter_plot ( 'scatter_1_default', data = data, width = 500, height = 500, border = 20, axis = True, grid = True )
 
162
    
 
163
    #lists of coordinates x,y
 
164
    data = [[1,2,3,4,5],[1,1,1,1,1]]
 
165
    cairoplot.scatter_plot ( 'scatter_2_lists', data = data, width = 500, height = 500, border = 20, axis = True, grid = True )
 
166
    
 
167
    #lists of coordinates x,y,z
 
168
    data = [[0.5,1,2,3,4,5],[0.5,1,1,1,1,1],[10,6,10,20,10,6]]
 
169
    colors = [ (0,0,0,0.25), (1,0,0,0.75) ]
 
170
    cairoplot.scatter_plot ( 'scatter_3_lists', data = data, width = 500, height = 500, border = 20, axis = True, discrete = True,
 
171
                             grid = True, circle_colors = colors )    
117
172
    
118
173
    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),
119
174
            (-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),
121
176
            (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),
122
177
            (-20, -13, 10), (-3, 5, 20), (-1, 13, 17), (-11, -9, 11)]
123
178
    colors = [ (0,0,0,0.25), (1,0,0,0.75) ]
124
 
    cairoplot.scatter_plot ( 'cross_2_variable_radius', data = data, width = 500, height = 500, border = 20, 
 
179
    cairoplot.scatter_plot ( 'scatter_2_variable_radius', data = data, width = 500, height = 500, border = 20, 
125
180
                             axis = True, discrete = True, dots = 2, grid = True, 
126
181
                             x_title = "x axis", y_title = "y axis", circle_colors = colors )
127
182
    
128
 
    #Scatter x DotLine
 
183
    #Scatter x DotLine error bars
129
184
    t = [x*0.1 for x in range(0,40)]
130
185
    f = [math.exp(x) for x in t]
131
186
    g = [10*math.cos(x) for x in t]
141
196
    
142
197
if test_themes :    
143
198
    data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
144
 
    cairoplot.bar_plot ( 'bar_color_themes', data, 400, 300, border = 20, grid = True, colors="rainbow" )
 
199
    cairoplot.vertical_bar_plot ( 'bar_color_themes', data, 400, 300, border = 20, grid = True, colors="rainbow" )
145
200
    
146
201
    data = [ lambda x : 1, lambda y : y**2, lambda z : -z**2 ]
147
202
    cairoplot.function_plot( 'function_color_themes', data, 400, 300, grid = True, series_colors = ["red", "orange", "yellow"], step = 0.1 )