def guide_granularity_20(self): G = Line('fohmnytenefohmnytene', encoding='simple') G.size(200, 100) G.axes.type('xy') G.axes.label('April', 'May', 'June') G.axes.label(None, '50+Kb') return G
def guide_granularity_40(self): G = Line('frothsmzndyoteepngenfrothsmzndyoteepngen', encoding='simple') G.size(200, 100) G.axes.type('xy') G.axes.label('April', 'May', 'June') G.axes.label(None, '50+Kb') return G
def markers(self): # Mark up some of the data randomly G = Line(['helloWorld']) G.marker('c', 'ff0000', 0, 3, 20) G.marker('d', '00ff00', 0, 6, 15) G.marker('a', '000099', 0, 4, 10) G.marker('R', 'A0BAE9', 0, 8, 0.6) G.marker('r', 'E5ECF9', 0, 1, 0.25) return G
def guide_granularity_80(self): G = Line( 'formostthisamazingdayfortheleapinggreenlformostthisamazingdayfortheleapinggreenl', encoding='simple') G.size(200, 100) G.axes.type('xy') G.axes.label('April', 'May', 'June') G.axes.label(None, '50+Kb') return G
def fill(self): # Fill the chart/background using chf, add axes to show bg G = Line(['pqokeYONOMEBAKPOQVTXZdecaZcglprqxuux393ztpoonkeggjp']) G.color('ff0000') G.line(4, 3, 0) G.axes.type('xy') G.axes.label(1, 2, 3, 4, 5) G.axes.label(None, 50, 100) G.fill('c', 'lg', 45, 'ffffff', 0, '76A4FB', 0.75) G.fill('bg', 's', 'EFEFEF') return G
def axes(self): # Call type first with the chxt # then call label and style in order, # label can contain None(s) G = Line(['foobarbaz']) G.color('76A4FB') G.axes.type('xyrx') G.axes.label('Foo', 'Bar', 'Baz') G.axes.label(None, '20K', '60K', '100K') G.axes.label('A', 'B', 'C') G.axes.label(None, '20', '40', '60', '80') G.axes.style('0000dd', 14) return G
def grid(self): # Create dashed line with grid x,y as floats # then, just like line, the line and blank segments G = Line(['foobarbaz']) G.color('76A4FB') G.line(3, 6, 3) G.grid(20.0, 25.0, 1, 0) return G
def graph_img(x, y, name): def y_precise(): result = ["chd=t:"] for elem in y: result.append(str(elem)) result.append(',') result[-1] = '&' return ''.join(result) G = Line(y, encoding='text') G.axes.type('xy') min_y = min(y) max_y = max(y) G.axes.range(1, min_y, max_y) G.scale(min_y, max_y) G.axes.label(0, x[0], x[-1]) G.axes.label(1, min_y, max_y) G.title(name) image_code = G.img() norm_img = re.sub(r'chd=t.*?\&', y_precise(), image_code) if len(norm_img) > 2000: if len(image_code) > 2000: raise LongPeriodException() else: return image_code return norm_img
def legend(self): # Add legend to the data set which follows collors G = Line(['FOETHECat', 'leafgreen', 'IRON4YOUs']) G.color('ff0000', '00ff00', '0000ff') G.legend('Animals', 'Vegetables', 'Minerals') G.axes.type('y') return G
def line(self): # Add red line 6 thick # with 5 line segments with 2 blank segments G = Line(['hX1xPj']) G.axes.type('xy') G.axes.label('Mar', 'Apr', 'May', 'June', 'July') G.axes.label(None, '50+Kb') G.color('ff0000') G.line(6, 5, 2) return G
def markerfill(self): # Fill the chart areas with markers G = Line([ '99', 'cefhjkqwrlgYcfgc', 'QSSVXXdkfZUMRTUQ', 'HJJMOOUbVPKDHKLH', 'AA' ]) G.marker('b', '76A4FB', 0, 1, 0) G.marker('b', '224499', 1, 2, 0) G.marker('b', 'FF0000', 2, 3, 0) G.marker('B', '80C65A', 3, 4, 0) return G
def title(self): # Title using name with optional color and size G = Line(['GurMrabsClgubaolGvzCrgrefOrnhgvshyvforggregunahtyl']) G.title('The Zen of Python', '00cc00', 36) G.color('00cc00') return G
def create_kml_file_for_level_stations( data_path="data/cehq_levels", kml_file_name="mon.kml", title="Water levels in meters", icon_color="ffffccee", icon_link="http://dl.dropbox.com/u/4629759/blue-L.png", data_url_format="", plot_daily_normals=False, plot_monthly_normals=False): stations = cehq_station.read_station_data(folder=data_path) width = 250 height = 100 kmlBody = ("") for s in stations: assert isinstance(s, cehq_station.Station) print(s.id) ##Monthly normals if plot_monthly_normals: values_monthly = s.get_monthly_normals() if values_monthly is None: print( "Skipping {0} since the data series is not continuous enough" .format(s.id)) continue # skip stations with incomplete data low = min(values_monthly) up = max(values_monthly) xy_monthly = Line((values_monthly - low) / (up - low) * 100.0) xy_monthly.axes.type("xyx") xy_monthly.size(width, height) xy_monthly.axes.range(0, 1, 12) xy_monthly.axes.range(1, low, up) xy_monthly.axes.label(2, None, "Month") #Daily normals if plot_daily_normals: times, values_daily = s.get_daily_normals() if values_daily is None: print( "Skipping {0} since the data series is not continuous enough" .format(s.id)) continue low = min(values_daily) up = max(values_daily) xy_daily = Line((values_daily - low) / (up - low) * 100.0) xy_daily.axes.type("xyx") xy_daily.size(width, height) xy_daily.axes.range(0, 1, 365) xy_daily.axes.range(1, low, up) xy_daily.axes.label(2, None, "Day") kml = (""" <Placemark>\n <name>%s</name>\n <Style> <IconStyle> <color>%s</color> <Icon> <href>%s</href> </Icon> </IconStyle> </Style> <description>\n <![CDATA[\n <p> <b> %s </b> </p> <p> Flow acc. area is %.1f km<sup>2<sup> </p> ]]>\n </description>\n <Point>\n <coordinates>%f, %f</coordinates>\n </Point>\n </Placemark>\n""") % (s.id, icon_color, icon_link, title, s.drainage_km2, s.longitude, s.latitude) kmlBody += kml #"morceaux" du fichier KML kmlHeader = ('<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n' '<kml xmlns=\"http://earth.google.com/kml/2.2\">\n' '<Document>\n') kmlFooter = ('</Document>\n' '</kml>\n') kmlFull = kmlHeader + kmlBody + kmlFooter open(kml_file_name, 'wb').write(kmlFull)
def guide_line_lc(self): G = Line('fooZaroo', encoding='simple') G.size(200, 100) return G
def graph(results): output = [] sorted_keys = results.keys() sorted_keys.sort() for test in sorted_keys: data = results[test] datalist = [data[host[0]] for host in HOSTS] plots = [] dates = [] max_points = max([len(d) for d in datalist]) for hostlist in datalist: hostplots = [] hostdates = [] for hostitem in hostlist: hostplots.append(hostitem[0]) hostdates.append(hostitem[1]) if len(hostplots) < max_points: hostplots.extend([ hostlist[-1][0] for i in xrange(max_points - len(hostplots)) ]) plots.append(hostplots) dates.append(hostdates) first_day = dates[0][0] last_day = dates[0][-1] delta = last_day - first_day diff = delta.days * 60 * 60 * 24 + delta.seconds days = [] days.append(first_day.strftime("%a")) days.append( (first_day + timedelta(seconds=int(diff * 0.2))).strftime("%a")) days.append( (first_day + timedelta(seconds=int(diff * 0.4))).strftime("%a")) days.append( (first_day + timedelta(seconds=int(diff * 0.6))).strftime("%a")) days.append( (first_day + timedelta(seconds=int(diff * 0.8))).strftime("%a")) days.append(last_day.strftime("%a")) maximum = max([max(d) for d in plots]) minimum = min([min(d) for d in plots]) def scale(value, scale=4095): return (value - minimum) * scale / abs(maximum - minimum) scaled_plots = [] for hostplots in plots: scaled_plots.append([scale(v) for v in hostplots]) g = Line(scaled_plots, encoding='extended') g.legend(*[host[1] for host in HOSTS]) g.legend_pos('b') g.color( "edc240", "afd8f8", "cb4b4b", "4da74d", "f8afe8", "4066ed", ) for i in range(3): g.line(2.5, 1, 0) g.size(500, 300) #g.scale(minimum, maximum) g.axes.type('xy') labels = range(minimum, maximum, (maximum - minimum) / 5) g.axes.label(0, *days) g.axes.label(1, *labels) #g.show() print test print g output.append("%s" % g)
def create_line(self): self._chart = Line([])
def graph(results): output = [] sorted_keys = results.keys() sorted_keys.sort() for test in sorted_keys: data = results[test] datalist = [data[host[0]] for host in HOSTS] plots = [] dates = [] max_points = max([len(d) for d in datalist]) for hostlist in datalist: hostplots = [] hostdates = [] for hostitem in hostlist: hostplots.append(hostitem[0]) hostdates.append(hostitem[1]) if len(hostplots) < max_points: hostplots.extend([hostlist[-1][0] for i in xrange(max_points-len(hostplots))]) plots.append(hostplots) dates.append(hostdates) first_day = dates[0][0] last_day = dates[0][-1] delta = last_day - first_day diff = delta.days*60*60*24 + delta.seconds days = [] days.append(first_day.strftime("%a")) days.append((first_day+timedelta(seconds=int(diff*0.2))).strftime("%a")) days.append((first_day+timedelta(seconds=int(diff*0.4))).strftime("%a")) days.append((first_day+timedelta(seconds=int(diff*0.6))).strftime("%a")) days.append((first_day+timedelta(seconds=int(diff*0.8))).strftime("%a")) days.append(last_day.strftime("%a")) maximum = max([max(d) for d in plots]) minimum = min([min(d) for d in plots]) def scale(value, scale=4095): return (value - minimum) * scale / abs(maximum - minimum) scaled_plots = [] for hostplots in plots: scaled_plots.append([scale(v) for v in hostplots]) g = Line(scaled_plots, encoding='extended') g.legend(*[host[1] for host in HOSTS]) g.legend_pos('b') g.color("edc240", "afd8f8", "cb4b4b", "4da74d", "f8afe8", "4066ed", ) for i in range(3): g.line(2.5, 1, 0) g.size(500, 300) #g.scale(minimum, maximum) g.axes.type('xy') labels = range(minimum, maximum, (maximum-minimum)/5) g.axes.label(0, *days) g.axes.label(1, *labels) #g.show() print test print g output.append("%s" % g)
def line_test(): G = Line([[0,10,20], [0,20,25]], encoding='text') #数据 simple模式和text模式 G.size(1000, 200) #整个图的大小 G.axes.type('xy') #XY两轴,可用xyz G.axes.label(0, 30) #设置0(x)轴标签 #G.axes.label(1, '5', '10', '15', '20', '25', '30') #设置1(Y)轴标签 #G.axes.range(0, 0, 5, 1) #设置0(x)轴范围 G.axes.range(1, 0, 50) #设置1(Y)轴范围 G.scale(0, 50) #设置放大比率,最小最大 G.fill('bg', 's', 'e0e0e0') #背景色 G.color('black', 'blue') #两条线的颜色 G.margin(20, 20, 20, 30, 80, 20) #表在图中的位置 G.legend('Merge', 'BigTable') #两标签名字 G.show() #网页显示
def create_kml_file_for_level_stations(data_path = "data/cehq_levels", kml_file_name = "mon.kml", title = "Water levels in meters", icon_color = "ffffccee", icon_link = "http://dl.dropbox.com/u/4629759/blue-L.png", data_url_format = "", plot_daily_normals = False, plot_monthly_normals = False ): stations = cehq_station.read_station_data(folder=data_path) width = 250 height = 100 kmlBody = ("") for s in stations: assert isinstance(s, cehq_station.Station) print(s.id) ##Monthly normals if plot_monthly_normals: values_monthly = s.get_monthly_normals() if values_monthly is None: print("Skipping {0} since the data series is not continuous enough".format(s.id)) continue # skip stations with incomplete data low = min(values_monthly) up = max(values_monthly) xy_monthly = Line((values_monthly - low) / (up - low) * 100.0) xy_monthly.axes.type("xyx") xy_monthly.size(width, height) xy_monthly.axes.range(0, 1,12) xy_monthly.axes.range(1, low, up) xy_monthly.axes.label(2, None, "Month") #Daily normals if plot_daily_normals: times, values_daily = s.get_daily_normals() if values_daily is None: print("Skipping {0} since the data series is not continuous enough".format(s.id)) continue low = min(values_daily) up = max(values_daily) xy_daily = Line((values_daily - low) / (up - low) * 100.0) xy_daily.axes.type("xyx") xy_daily.size(width, height) xy_daily.axes.range(0, 1,365) xy_daily.axes.range(1, low, up) xy_daily.axes.label(2, None, "Day") kml = ( """ <Placemark>\n <name>%s</name>\n <Style> <IconStyle> <color>%s</color> <Icon> <href>%s</href> </Icon> </IconStyle> </Style> <description>\n <![CDATA[\n <p> <b> %s </b> </p> <p> Flow acc. area is %.1f km<sup>2<sup> </p> ]]>\n </description>\n <Point>\n <coordinates>%f, %f</coordinates>\n </Point>\n </Placemark>\n""" ) % ( s.id, icon_color, icon_link, title, s.drainage_km2, s.longitude, s.latitude) kmlBody += kml #"morceaux" du fichier KML kmlHeader = ('<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n' '<kml xmlns=\"http://earth.google.com/kml/2.2\">\n' '<Document>\n') kmlFooter = ('</Document>\n' '</kml>\n') kmlFull = kmlHeader + kmlBody + kmlFooter open(kml_file_name,'wb').write(kmlFull)
def margins_test(): G = Line([[8,12,11,16,22],[7,8,10,12,19,23]], encoding='simple') #实际数据 G.size(1000, 200) #整个图大小 G.label(1,5,10,20,40,60,100,160,260,420,68,1100,1780) #下标量 G.fill('bg', 's', 'e0e0e0') #背景 G.color('black', 'blue') #线颜色 G.margin(20,20,20,30,80,20) #图位置 G.legend('Merge', 'BigTable') #线标签 print G