1
import cairo, math, random
4
from Series import Serie
11
test_vertical_bar_plot = 1
12
test_horizontal_bar_plot = 1
23
data = Serie([ (-2,10), (0,0), (0,15), (1,5), (2,0), (3,-10), (3,5) ])
24
cairoplot.scatter_plot ( 'scatter_1_default_series.png', data = data, width = 500, height = 500, border = 20, axis = True, grid = True )
26
#lists of coordinates x,y
27
data = Serie([[[1,2,3,4,5],[1,1,1,1,1]]])
28
cairoplot.scatter_plot ( 'scatter_2_lists_series.png', data = data, width = 500, height = 500, border = 20, axis = True, grid = True )
30
#lists of coordinates x,y,z
31
data = Serie([[[0.5,1,2,3,4,5],[0.5,1,1,1,1,1],[10,6,10,20,10,6]]])
32
colors = [ (0,0,0,0.25), (1,0,0,0.75) ]
33
cairoplot.scatter_plot ( 'scatter_3_lists_series.png', data = data, width = 500, height = 500, border = 20, axis = True, discrete = True,
34
grid = True, circle_colors = colors )
36
data = Serie([(-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),
37
(-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),
38
(-20, -6, 17), (-10, -10, 12), (-7, 17, 25), (10, -10, 13), (10, 13, 20), (17, 6, 15), (18, -11, 14), (18, -12, 11), (-9, 11, 14),
39
(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),
40
(-20, -13, 10), (-3, 5, 20), (-1, 13, 17), (-11, -9, 11)])
41
colors = [ (0,0,0,0.25), (1,0,0,0.75) ]
42
cairoplot.scatter_plot ( 'scatter_2_variable_radius_series.png', data = data, width = 500, height = 500, border = 20,
43
axis = True, discrete = True, dots = 2, grid = True,
44
x_title = "x axis", y_title = "y axis", circle_colors = colors )
46
#Scatter x DotLine error bars
47
t = [x*0.1 for x in range(0,40)]
48
f = [math.exp(x) for x in t]
49
g = [10*math.cos(x) for x in t]
50
h = [10*math.sin(x) for x in t]
51
erx = [0.1*random.random() for x in t]
52
ery = [5*random.random() for x in t]
53
data = Serie({"exp" : [t,f], "cos" : [t,g], "sin" : [t,h]})
54
series_colors = [ (1,0,0), (0,0,0), (0,0,1) ]
55
cairoplot.scatter_plot ( 'cross_r_exponential_series.png', data = data, errorx = [erx,erx], errory = [ery,ery], width = 800, height = 600, border = 20,
56
axis = True, discrete = False, dots = 5, grid = True,
57
x_title = "t", y_title = "f(t) g(t)", series_legend=True, series_colors = series_colors )
60
if test_dot_line_plot:
62
data = [ 0, 1, 3.5, 8.5, 9, 0, 10, 10, 2, 1 ]
63
cairoplot.dot_line_plot( "dot_line_1_default_series.png", data, 400, 300, border = 50, axis = True, grid = True,
64
x_title = "x axis", y_title = "y axis" )
67
data = { "john" : [-5, -2, 0, 1, 3], "mary" : [0, 0, 3, 5, 2], "philip" : [-2, -3, -4, 2, 1] }
68
x_labels = [ "jan/2008", "feb/2008", "mar/2008", "apr/2008", "may/2008" ]
69
y_labels = [ "very low", "low", "medium", "high", "very high" ]
70
cairoplot.dot_line_plot( "dot_line_2_dictionary_labels_series.png", data, 400, 300, x_labels = x_labels,
71
y_labels = y_labels, axis = True, grid = True,
72
x_title = "x axis", y_title = "y axis", series_legend=True )
75
data = { "john" : [10, 10, 10, 10, 30], "mary" : [0, 0, 3, 5, 15], "philip" : [13, 32, 11, 25, 2] }
76
x_labels = [ "jan/2008", "feb/2008", "mar/2008", "apr/2008", "may/2008" ]
77
cairoplot.dot_line_plot( 'dot_line_3_series_legend_series.png', data, 400, 300, x_labels = x_labels,
78
axis = True, grid = True, series_legend = True )
80
if test_function_plot :
82
data = lambda x : x**2
83
cairoplot.function_plot( 'function_1_default_series.png', data, 400, 300, grid = True, x_bounds=(-10,10), step = 0.1 )
86
data = lambda x : math.sin(0.1*x)*math.cos(x)
87
cairoplot.function_plot( 'function_2_discrete_series.png', data, 800, 300, discrete = True, dots = True, grid = True, x_bounds=(0,80),
88
x_title = "t (s)", y_title = "sin(0.1*x)*cos(x)")
91
data = lambda x : [1,2,3,4,5][x]
92
x_labels = [ "4", "3", "2", "1", "0" ]
93
cairoplot.function_plot( 'function_3_labels_series.png', data, 400, 300, discrete = True, dots = True, grid = True, x_labels = x_labels, x_bounds=(0,4), step = 1 )
96
data = [ lambda x : 1, lambda y : y**2, lambda z : -z**2 ]
97
colors = [ (1.0, 0.0, 0.0 ), ( 0.0, 1.0, 0.0 ), ( 0.0, 0.0, 1.0 ) ]
98
cairoplot.function_plot( 'function_4_multi_functions_series.png', data, 400, 300, grid = True, series_colors = colors, step = 0.1 )
104
gaussian = lambda x : a*math.exp(-(x-b)*(x-b)/(2*c*c))
105
cairoplot.function_plot( 'function_5_gaussian_series.png', data, 400, 300, grid = True, x_bounds = (-10,10), step = 0.1 )
110
data.group_list = {'linear':lambda x : x*2, 'quadratic':lambda x:x**2, 'cubic':lambda x:(x**3)/2}
111
cairoplot.function_plot( 'function_6_dict_serie.png', data, 400, 300, grid = True, x_bounds=(-5,5), step = 0.1 )
114
if test_vertical_bar_plot:
115
#Passing a dictionary
116
data = Serie({ 'teste00' : [27], 'teste01' : [10], 'teste02' : [18], 'teste03' : [5], 'teste04' : [1], 'teste05' : [22] })
117
cairoplot.vertical_bar_plot ( 'vbar_0_dictionary_series.png', data, 400, 300, border = 20, grid = True, rounded_corners = True )
120
data = Serie({ 'teste00' : [27], 'teste01' : [10], 'teste02' : [18], 'teste03' : [5], 'teste04' : [1], 'teste05' : [22] })
121
cairoplot.vertical_bar_plot ( 'vbar_0_dictionary_series.png', data, 400, 300, border = 20, display_values = True, grid = True, rounded_corners = True )
123
#Using default, rounded corners and 3D visualization
124
data = Serie([ [0, 3, 11], [8, 9, 21], [13, 10, 9], [2, 30, 8] ])
125
colors = [ (1,0.2,0), (1,0.7,0), (1,1,0) ]
126
series_labels = ["red", "orange", "yellow"]
127
cairoplot.vertical_bar_plot ( 'vbar_1_default_series.png', data, 400, 300, border = 20, grid = True, rounded_corners = False, colors = "yellow_orange_red" )
128
cairoplot.vertical_bar_plot ( 'vbar_2_rounded_series.png', data, 400, 300, border = 20, series_labels = series_labels, display_values = True, grid = True, rounded_corners = True, colors = colors )
129
cairoplot.vertical_bar_plot ( 'vbar_3_3D_series.png', data, 400, 300, border = 20, series_labels = series_labels, grid = True, three_dimension = True, colors = colors )
131
#Mixing groups and columns
132
data = Serie([ [1], [2], [3,4], [4], [5], [6], [7], [8], [9], [10] ])
133
cairoplot.vertical_bar_plot ( 'vbar_4_group_series.png', data, 400, 300, border = 20, grid = True )
135
#Using no labels, horizontal and vertical labels
136
data = Serie([[3,4], [4,8], [5,3], [9,1]])
137
y_labels = [ "line1", "line2", "line3", "line4", "line5", "line6" ]
138
x_labels = [ "group1", "group2", "group3", "group4" ]
139
cairoplot.vertical_bar_plot ( 'vbar_5_no_labels_series.png', data, 600, 200, border = 20, grid = True )
140
cairoplot.vertical_bar_plot ( 'vbar_6_x_labels_series.png', data, 600, 200, border = 20, grid = True, x_labels = x_labels )
141
cairoplot.vertical_bar_plot ( 'vbar_7_y_labels_series.png', data, 600, 200, border = 20, grid = True, y_labels = y_labels )
142
cairoplot.vertical_bar_plot ( 'vbar_8_hy_labels_series.png', data, 600, 200, border = 20, display_values = True, grid = True, x_labels = x_labels, y_labels = y_labels )
145
data = Serie([[10*random.random()] for x in range(50)])
146
x_labels = ["large label name oh my god it's big" for x in data]
147
cairoplot.vertical_bar_plot ( 'vbar_9_large_series.png', data, 1000, 800, border = 20, grid = True, rounded_corners = True, x_labels = x_labels )
150
data = Serie([ [6, 4, 10], [8, 9, 3], [1, 10, 9], [2, 7, 11] ])
151
colors = [ (1,0.2,0), (1,0.7,0), (1,1,0) ]
152
x_labels = ["teste1", "teste2", "testegrande3", "testegrande4"]
153
cairoplot.vertical_bar_plot ( 'vbar_10_stack_series.png', data, 400, 300, border = 20, display_values = True, grid = True, rounded_corners = True, stack = True,
154
x_labels = x_labels, colors = colors )
157
if test_horizontal_bar_plot:
158
#Passing a dictionary
159
data = Serie({ 'teste00' : [27], 'teste01' : [10], 'teste02' : [18], 'teste03' : [5], 'teste04' : [1], 'teste05' : [22] })
160
cairoplot.horizontal_bar_plot ( 'hbar_0_dictionary_series.png', data, 400, 300, border = 20, display_values = True, grid = True, rounded_corners = True )
162
#Using default, rounded corners and 3D visualization
163
data = Serie([ [0, 3, 11], [8, 9, 21], [13, 10, 9], [2, 30, 8] ])
164
colors = [ (1,0.2,0), (1,0.7,0), (1,1,0) ]
165
series_labels = ["red", "orange", "yellow"]
166
cairoplot.horizontal_bar_plot ( 'hbar_1_default_series.png', data, 400, 300, border = 20, grid = True, rounded_corners = False, colors = "yellow_orange_red" )
167
cairoplot.horizontal_bar_plot ( 'hbar_2_rounded_series.png', data, 400, 300, border = 20, series_labels = series_labels, display_values = True, grid = True, rounded_corners = True, colors = colors )
170
#Mixing groups and columns
171
data = ([ [1], [2], [3,4], [4], [5], [6], [7], [8], [9], [10] ])
172
cairoplot.horizontal_bar_plot ( 'hbar_4_group_series.png', data, 400, 300, border = 20, grid = True )
174
#Using no labels, horizontal and vertical labels
175
series_labels = ["data11", "data22"]
176
data = Serie([[3,4], [4,8], [5,3], [9,1]])
177
x_labels = [ "line1", "line2", "line3", "line4", "line5", "line6" ]
178
y_labels = [ "group1", "group2", "group3", "group4" ]
179
cairoplot.horizontal_bar_plot ( 'hbar_5_no_labels_series.png', data, 600, 200, border = 20, series_labels = series_labels, grid = True )
180
cairoplot.horizontal_bar_plot ( 'hbar_6_x_labels_series.png', data, 600, 200, border = 20, series_labels = series_labels, grid = True, x_labels = x_labels )
181
cairoplot.horizontal_bar_plot ( 'hbar_7_y_labels_series.png', data, 600, 200, border = 20, series_labels = series_labels, grid = True, y_labels = y_labels )
182
cairoplot.horizontal_bar_plot ( 'hbar_8_hy_labels_series.png', data, 600, 200, border = 20, series_labels = series_labels, display_values = True, grid = True, x_labels = x_labels, y_labels = y_labels )
185
data = Serie([[10*random.random()] for x in range(25)])
186
x_labels = ["large label name oh my god it's big" for x in data]
187
cairoplot.horizontal_bar_plot ( 'hbar_9_large_series.png', data, 1000, 800, border = 20, grid = True, rounded_corners = True, x_labels = x_labels )
190
data = Serie([ [6, 4, 10], [8, 9, 3], [1, 10, 9], [2, 7, 11] ])
191
colors = [ (1,0.2,0), (1,0.7,0), (1,1,0) ]
192
y_labels = ["teste1", "teste2", "testegrande3", "testegrande4"]
193
cairoplot.horizontal_bar_plot ( 'hbar_10_stack_series.png', data, 400, 300, border = 20, display_values = True, grid = True, rounded_corners = True, stack = True,
194
y_labels = y_labels, colors = colors )
197
#Define a new backgrond
198
background = cairo.LinearGradient(300, 0, 300, 400)
199
background.add_color_stop_rgb(0.0,0.7,0.0,0.0)
200
background.add_color_stop_rgb(1.0,0.3,0.0,0.0)
203
data = {"orcs" : 100, "goblins" : 230, "elves" : 50 , "demons" : 43, "humans" : 332}
204
cairoplot.pie_plot( "pie_1_default_series.png", data, 600, 400 )
205
cairoplot.pie_plot( "pie_2_gradient_shadow_series.png", data, 600, 400, gradient = True, shadow = True )
206
cairoplot.pie_plot( "pie_3_background_series.png", data, 600, 400, background = background, gradient = True, shadow = True )
209
#Define a new backgrond
210
background = cairo.LinearGradient(300, 0, 300, 400)
211
background.add_color_stop_rgb(0,0.4,0.4,0.4)
212
background.add_color_stop_rgb(1.0,0.1,0.1,0.1)
214
data = {"john" : 700, "mary" : 100, "philip" : 100 , "suzy" : 50, "yman" : 50}
215
#Default plot, gradient and shadow, different background
216
cairoplot.donut_plot( "donut_1_default_series.png", data, 600, 400, inner_radius = 0.3 )
217
cairoplot.donut_plot( "donut_2_gradient_shadow_series.png", data, 600, 400, gradient = True, shadow = True, inner_radius = 0.3 )
218
cairoplot.donut_plot( "donut_3_background_series.png", data, 600, 400, background = background, gradient = True, shadow = True, inner_radius = 0.3 )
220
if test_gantt_chart :
222
pieces = Serie([(0.5, 5.5), [(0, 4), (6, 8)], (5.5, 7), (7, 9)])
223
x_labels = [ 'teste01', 'teste02', 'teste03', 'teste04']
224
y_labels = [ '0001', '0002', '0003', '0004', '0005', '0006', '0007', '0008', '0009', '0010' ]
225
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) ]
226
cairoplot.gantt_chart('gantt_1_default_series.png', pieces, 500, 350, x_labels, y_labels, colors)
229
data = Serie([[1,2,3,4,5,6,7,8,9,10,11,12,13,14]])
230
cairoplot.vertical_bar_plot ( 'bar_1_color_themes_series.png', data, 400, 300, border = 20, grid = True, colors="rainbow" )
232
data = Serie([[1,2,3,4,5,6,7,8,9,10,11,12,13,14]])
233
cairoplot.vertical_bar_plot ( 'bar_2_color_themes_series.png', data, 400, 300, background = "white light_gray", border = 20, grid = True, colors="rainbow" )
236
data.range = (0,10,0.1)
237
data.group_list = [ lambda x : 1, lambda y : y**2, lambda z : -z**2 ]
238
cairoplot.function_plot( 'function_color_themes_series.png', data, 400, 300, grid = True, series_colors = ["red", "orange", "yellow"], step = 0.1 )
241
t = [x*0.1 for x in range(0,40)]
242
f = [math.exp(x) for x in t]
243
g = [10*math.cos(x) for x in t]
244
h = [10*math.sin(x) for x in t]
245
erx = [0.1*random.random() for x in t]
246
ery = [5*random.random() for x in t]
247
data = Serie({"exp" : [t,f], "cos" : [t,g], "sin" : [t,h]})
248
series_colors = [ (1,0,0), (0,0,0) ]
249
cairoplot.scatter_plot ( 'scatter_color_themes_series.png', data = data, errorx = [erx,erx], errory = [ery,ery], width = 800, height = 600, border = 20,
250
axis = True, discrete = False, dots = 5, grid = True,
251
x_title = "t", y_title = "f(t) g(t)", series_legend=True, series_colors = ["red", "blue", "orange"])