예제 #1
0
파일: ctba.py 프로젝트: odin793/ctba
	def plot_graph_3(self, d, picture_filename):
		"""
		time in is row[2]
		time out is row[4]
		minutes_spanded is row[6]
		"""

		import sys
		sys.path.append('/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages')
		
		import cairo
		import cairoplot
		from random import random
		
		self.write_report('graph_3.html', {'graph_3_date': d})
		
		v_legend = map(str, range(25))
		graph_3_data = [row for row in self.filter_rows(d, d) if self.is_service(row)]
		if not graph_3_data:
			cairoplot.gantt_chart(picture_filename, [[(5,19)]], 1000, 900, ['no_data',], v_legend, [(1,0,0),])
			print 'graph 3 successfully plotted. no data'
			return

		unique_ids = set([row[0] for row in graph_3_data])
		grouped_data = {}

		# bug or feature of cairoplot:
		# if there was one time_in_out for each id - we should
		# wrap each time_in_out pair in list, ex. [[(3, 6)], [(8, 12)]]
		# else: we should not 
		# that's why we use several_mode flag
		several_mode = False
		for client_id in unique_ids:
			client_id_rows = [row for row in graph_3_data if row[0] == client_id]
			if len(client_id_rows) > 1:
				several_mode = True
				time_in_out = [self.get_time_in_out_pair(row) for row in client_id_rows]
			else:
				time_in_out = self.get_time_in_out_pair(client_id_rows[0])
			
			grouped_data[client_id] = time_in_out
		
		if several_mode:
			pieces = grouped_data.values()
		else:
			pieces = map(lambda x: [x], grouped_data.values())
		h_legend = map(lambda x: 'id ' + x, grouped_data.keys())
		
		colors = [(random(), random(), random()) for piece in pieces]
		
		cairoplot.gantt_chart(picture_filename, pieces, 1000, 900, h_legend, v_legend, colors)
		print 'graph 3 successfully plotted'
예제 #2
0
    background.add_color_stop_rgb(0,0.4,0.4,0.4)
    background.add_color_stop_rgb(1.0,0.1,0.1,0.1)
    
    data = {"john" : 700, "mary" : 100, "philip" : 100 , "suzy" : 50, "yman" : 50}
    #Default plot, gradient and shadow, different background
    cairoplot.donut_plot( "donut_1_default_series.png", data, 600, 400, inner_radius = 0.3 )
    cairoplot.donut_plot( "donut_2_gradient_shadow_series.png", data, 600, 400, gradient = True, shadow = True, inner_radius = 0.3 )
    cairoplot.donut_plot( "donut_3_background_series.png", data, 600, 400, background = background, gradient = True, shadow = True, inner_radius = 0.3 )

if test_gantt_chart :
    #Default Plot
    pieces = Series([(0.5, 5.5), [(0, 4), (6, 8)], (5.5, 7), (7, 9)])
    x_labels = [ 'teste01', 'teste02', 'teste03', 'teste04']
    y_labels = [ '0001', '0002', '0003', '0004', '0005', '0006', '0007', '0008', '0009', '0010' ]
    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) ]
    cairoplot.gantt_chart('gantt_1_default_series.png', pieces, 500, 350, x_labels, y_labels, colors)
    
if test_themes :    
    data = Series([[1,2,3,4,5,6,7,8,9,10,11,12,13,14]])
    cairoplot.vertical_bar_plot ( 'bar_1_color_themes_series.png', data, 400, 300, border = 20, grid = True, colors="rainbow" )
    
    data = Series([[1,2,3,4,5,6,7,8,9,10,11,12,13,14]])
    cairoplot.vertical_bar_plot ( 'bar_2_color_themes_series.png', data, 400, 300, background = "white light_gray", border = 20, grid = True, colors="rainbow" )
    
    data = Series()
    data.range = (0,10,0.1)
    data.group_list = [ lambda x : 1, lambda y : y**2, lambda z : -z**2 ]
    cairoplot.function_plot( 'function_color_themes_series.png', data, 400, 300, grid = True, series_colors = ["red", "orange", "yellow"], step = 0.1 )
    
    #Scatter x DotLine
    t = [x*0.1 for x in range(0,40)]