Python pygal.Line() Examples
The following are 19
code examples of pygal.Line().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pygal
, or try the search function
.
Example #1
Source File: line_graph.py From python_course with Apache License 2.0 | 6 votes |
def twoline(file_name, title, line1, line1_label, line2, line2_label, x_labels): """ Line1 is a list of data points Line2 is a list of data points x_labels are labels that correspond to the data points in line1 and line2 Example call: line_graph.twoline("pynet-rtr1-octets.svg", "pynet-rtr1 Fa4 Input/Output Bytes", in_octets_list, "In Octets", out_octets_list, "Out Octets", x_labels_list): """ line_chart = pygal.Line(include_x_axis=True) line_chart.title = title line_chart.x_labels = x_labels line_chart.add(line1_label, line1) line_chart.add(line2_label, line2) line_chart.render_to_file(file_name) return True
Example #2
Source File: line_graph.py From pynet with Apache License 2.0 | 6 votes |
def twoline(file_name, title, line1, line1_label, line2, line2_label, x_labels): ''' Line1 is a list of data points Line2 is a list of data points x_labels are labels that correspond to the data points in line1 and line2 Example call: line_graph.twoline("pynet-rtr1-octets.svg", "pynet-rtr1 Fa4 Input/Output Bytes", in_octets_list, "In Octets", out_octets_list, "Out Octets", x_labels_list): ''' line_chart = pygal.Line(include_x_axis=True) line_chart.title = title line_chart.x_labels = x_labels line_chart.add(line1_label, line1) line_chart.add(line2_label, line2) line_chart.render_to_file(file_name) return True
Example #3
Source File: line_graph.py From pynet with Apache License 2.0 | 6 votes |
def twoline(file_name, title, line1, line1_label, line2, line2_label, x_labels): ''' Line1 is a list of data points Line2 is a list of data points x_labels are labels that correspond to the data points in line1 and line2 Example call: line_graph.twoline("pynet-rtr1-octets.svg", "pynet-rtr1 Fa4 Input/Output Bytes", in_octets_list, "In Octets", out_octets_list, "Out Octets", x_labels_list): ''' line_chart = pygal.Line(include_x_axis=True) line_chart.title = title line_chart.x_labels = x_labels line_chart.add(line1_label, line1) line_chart.add(line2_label, line2) line_chart.render_to_file(file_name) return True
Example #4
Source File: analyze.py From ok with Apache License 2.0 | 6 votes |
def generate_line_chart(backups, cid, email, aid): """ Generates a pygal line_chart given a list of backups """ points, timestamps = _get_graph_points(backups, cid, email, aid) line_chart = pygal.Line(disable_xml_declaration=True, human_readable=True, legend_at_bottom=True, pretty_print=True, show_legend=False ) line_chart.title = 'Lines/Minutes Ratio Across Backups: {0}'.format(email) line_chart.add('Backups', points) line_chart.x_labels = timestamps return line_chart
Example #5
Source File: HumidityChart.py From mvp with MIT License | 6 votes |
def buildChart(data): '''Build the chard from array data''' v_lst=[] ts_lst=[] for row in data: # print row["start_date"]["timestamp"], row["subject"]["attribute"]["value"] v_lst.append(float(row["subject"]["attribute"]["value"])) ts_lst.append(row["start_date"]["timestamp"]) line_chart = pygal.Line() line_chart.title = 'Humidity' line_chart.y_title="Percent" line_chart.x_title="Timestamp (hover over to display date)" #need to reverse order to go from earliest to latest ts_lst.reverse() line_chart.x_labels = ts_lst #need to reverse order to go from earliest to latest v_lst.reverse() line_chart.add('Humidity', v_lst) line_chart.render_to_file('/home/pi/MVP/web/humidity_chart.svg')
Example #6
Source File: TempChart.py From mvp with MIT License | 6 votes |
def buildChart(data): '''Build the chard from array data''' v_lst=[] ts_lst=[] for row in data: # print row["start_date"]["timestamp"], row["subject"]["attribute"]["value"] v_lst.append(float(row["subject"]["attribute"]["value"])) ts_lst.append(UTCStrToLDT(row["start_date"]["timestamp"])) line_chart = pygal.Line() line_chart.title = 'Temperature' line_chart.y_title="Degrees C" line_chart.x_title="Timestamp (hover over to display date)" #need to reverse order to go from earliest to latest ts_lst.reverse() line_chart.x_labels = ts_lst #need to reverse order to go from earliest to latest v_lst.reverse() line_chart.add('Air Temp', v_lst) line_chart.render_to_file('/home/pi/MVP/web/temp_chart.svg')
Example #7
Source File: benchmark.py From SNIPER-mxnet with Apache License 2.0 | 5 votes |
def plot_graph(args): speedup_chart = pygal.Line(x_title='gpus', y_title='speedup', logarithmic=True) speedup_chart.x_labels = map(str, series(args.worker_count * args.gpu_count)) speedup_chart.add('ideal speedup', series(args.worker_count * args.gpu_count)) for net in args.networks: image_single_gpu = net.gpu_speedup[1] if 1 in net.gpu_speedup or not net.gpu_speedup[1] else 1 y_values = [each / image_single_gpu for each in net.gpu_speedup.values()] LOGGER.info('%s: image_single_gpu:%.2f' % (net.name, image_single_gpu)) LOGGER.debug('network:%s, y_values: %s' % (net.name, ' '.join(map(str, y_values)))) speedup_chart.add(net.name, y_values \ , formatter=lambda y_val, img=copy.deepcopy(image_single_gpu), batch_size=copy.deepcopy( net.batch_size): 'speedup:%.2f, img/sec:%.2f, batch/gpu:%d' % \ (0 if y_val is None else y_val, 0 if y_val is None else y_val * img, batch_size)) speedup_chart.render_to_file(log_loc + '/speedup.svg')
Example #8
Source File: benchmark.py From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 | 5 votes |
def plot_graph(args): speedup_chart = pygal.Line(x_title='gpus', y_title='speedup', logarithmic=True) speedup_chart.x_labels = map(str, series(args.worker_count * args.gpu_count)) speedup_chart.add('ideal speedup', series(args.worker_count * args.gpu_count)) for net in args.networks: image_single_gpu = net.gpu_speedup[1] if 1 in net.gpu_speedup or not net.gpu_speedup[1] else 1 y_values = [each / image_single_gpu for each in net.gpu_speedup.values()] LOGGER.info('%s: image_single_gpu:%.2f' % (net.name, image_single_gpu)) LOGGER.debug('network:%s, y_values: %s' % (net.name, ' '.join(map(str, y_values)))) speedup_chart.add(net.name, y_values \ , formatter=lambda y_val, img=copy.deepcopy(image_single_gpu), batch_size=copy.deepcopy( net.batch_size): 'speedup:%.2f, img/sec:%.2f, batch/gpu:%d' % \ (0 if y_val is None else y_val, 0 if y_val is None else y_val * img, batch_size)) speedup_chart.render_to_file(log_loc + '/speedup.svg')
Example #9
Source File: btc_close_2017.py From Python-Project with Apache License 2.0 | 5 votes |
def draw_line(x_data, y_data, title, y_legend): xy_map = [] for x, y in groupby(sorted(zip(x_data, y_data)), key=lambda _: _[0]): # 2 y_list = [v for _, v in y] xy_map.append([x, sum(y_list) / len(y_list)]) # 3 x_unique, y_mean = [*zip(*xy_map)] # 4 line_chart = pygal.Line() line_chart.title = title line_chart.x_labels = x_unique line_chart.add(y_legend, y_mean) line_chart.render_to_file(title + '.svg') return line_chart # 绘制2017年前11个月的日均值
Example #10
Source File: app.py From moa with MIT License | 5 votes |
def user_graph(): hours = int(request.args.get('hours', 24)) since = datetime.now() - timedelta(hours=hours) stats_query = db.session.query(Bridge).filter(Bridge.created > since).filter(Bridge.enabled == 1).with_entities( Bridge.created) base_count_query = db.session.query(func.count(Bridge.id)).scalar() df = pd.read_sql(stats_query.statement, stats_query.session.bind) df.set_index(['created'], inplace=True) df['count'] = 1 # app.logger.info(df) # df.groupby(level=0).sum() r = df.resample('d').sum() r = r.fillna(0) r['cum_sum'] = r['count'].cumsum() + base_count_query # app.logger.info(r) users = r['cum_sum'].tolist() # app.logger.info(users) chart = pygal.Line(title=f"# of Users ({timespan(hours)})", stroke_style={'width': 5}, show_legend=False) chart.add('Users', users, fill=True, show_dots=False) return chart.render_response()
Example #11
Source File: pic_ali.py From bbotte.github.io with Apache License 2.0 | 5 votes |
def pic(self): line_chart = pygal.Line() line_chart.title = txt_id line_chart.x_labels = map(str, txt_t) line_chart.add(txt_id, txt_a) line_chart.render_to_file('bar_chart.svg')
Example #12
Source File: aliyun_picture.py From bbotte.github.io with Apache License 2.0 | 5 votes |
def getEcsMetric(metric, uid, key, userid, instanceid): clt = client.AcsClient(uid,key,'cn-qingdao') startTime=datetime.datetime.now() - datetime.timedelta(hours=1) startTimeStr=startTime.strftime("%Y-%m-%d %H:%M:%S") request = QueryMetricRequest.QueryMetricRequest() request.set_accept_format('json') request.set_Project('acs_ecs') request.set_Metric(metric) request.set_StartTime(startTimeStr) request.set_Dimensions("{userId:'%s', instanceId:'%s'}" % (userid,instanceid)) ret = clt.do_action(request) print(ret) data_json = json.loads(ret) rawdata = data_json["Datapoints"]["Datapoint"] for i in range(len(rawdata)): formatdata = (str(rawdata[i]["timestamp"]))[:10] txt_time = datetime.datetime.fromtimestamp(int(formatdata)).strftime('%Y-%m-%d %H:%M:%S') txt_t.append(txt_time) txt_content.append(rawdata[i]["Average"]) txt_id = '%s' % (instanceid) line_chart = pygal.Line() line_chart.title = txt_id line_chart.x_labels = map(str, txt_content) line_chart.add(txt_id, txt_content) line_chart.render_to_file('ecs.svg')
Example #13
Source File: benchmark.py From training_results_v0.6 with Apache License 2.0 | 5 votes |
def plot_graph(args): speedup_chart = pygal.Line(x_title='gpus', y_title='speedup', logarithmic=True) speedup_chart.x_labels = map(str, series(args.worker_count * args.gpu_count)) speedup_chart.add('ideal speedup', series(args.worker_count * args.gpu_count)) for net in args.networks: image_single_gpu = net.gpu_speedup[1] if 1 in net.gpu_speedup or not net.gpu_speedup[1] else 1 y_values = [each / image_single_gpu for each in net.gpu_speedup.values()] LOGGER.info('%s: image_single_gpu:%.2f' % (net.name, image_single_gpu)) LOGGER.debug('network:%s, y_values: %s' % (net.name, ' '.join(map(str, y_values)))) speedup_chart.add(net.name, y_values \ , formatter=lambda y_val, img=copy.deepcopy(image_single_gpu), batch_size=copy.deepcopy( net.batch_size): 'speedup:%.2f, img/sec:%.2f, batch/gpu:%d' % \ (0 if y_val is None else y_val, 0 if y_val is None else y_val * img, batch_size)) speedup_chart.render_to_file(log_loc + '/speedup.svg')
Example #14
Source File: views.py From edwin with Apache License 2.0 | 4 votes |
def raw_svgs(): chart = pygal.Line(legend_at_bottom=True, legend_box_size=18) # ======================================= # Declare the location of svg.jquery.js and pygal-tooltips.js in server side. # ======================================= # It must be declare in server side, not html file # if not declare in server, by default it will load the two js files located in http://kozea.github.com/pygal.js. And it will slow down the page loading # 1, It works, load local js files SITE_ROOT = os.path.realpath(os.path.dirname(__file__)) chart.js = [os.path.join(SITE_ROOT, "static/js/", "svg.jquery.js"), os.path.join(SITE_ROOT, "static/js/", "pygal-tooltips.js")] # 2.a, It Works, but it is ugly because it use local absolute http url # chart.js =['http://127.0.0.1:5000/static/js/svg.jquery.js', # 'http://127.0.0.1:5000/static/js/pygal-tooltips.js'] # 2.b, works, use local CDN absolute http url # chart.js =['http://another_server/pygal-tooltips.js', # 'http://another_server/svg.jquery.js'] # 3, Does not work, error raised at visiting, IOError: [Errno 2] No such file # chart.js = [url_for('static', filename='js/svg.jquery.js'), # url_for('static', filename='js/pygal-tooltips.js')] # disable xml root node chart.disable_xml_declaration = True chart.title = 'Browser usage evolution (in %)' chart.width = 2000 chart.height = 2000 chart.x_labels = map(str, range(2002, 2013)) chart.add('Firefox', [None, None, 0, 16.6, 25, 31, 36.4, 45.5, 46.3, 42.8, 37.1]) chart.add('Chrome', [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3]) chart.add('IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1]) chart.add('Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5]) svg_xml = chart.render() svg_xml = '<svg style="width:2000px" ' + svg_xml[4:] svg_xml1 = svg_xml[:100] response = make_response(render_template('test_svg.html', title=svg_xml1, svg_xml=svg_xml)) # response.headers['Content-Type']='image/svg+xml' 不能设置Content-Type为svg模式 return response
Example #15
Source File: app.py From moa with MIT License | 4 votes |
def time_graph(): hours = int(request.args.get('hours', 24)) since = datetime.now() - timedelta(hours=hours) stats_query = db.session.query(WorkerStat).filter(WorkerStat.created > since).with_entities(WorkerStat.created, WorkerStat.time, WorkerStat.worker) df = pd.read_sql(stats_query.statement, stats_query.session.bind) dfs = {} rs = {} l_1 = 0 times = {} main_times = pd.DataFrame({'A': []}) chart = pygal.Line(title=f"Worker run time (s) ({timespan(hours)})", stroke_style={'width': 2}, legend_at_bottom=True) i = 1 while i <= app.config['WORKER_JOBS']: dfs[i] = df[df['worker'] == i] dfs[i].set_index(['created'], inplace=True) dfs[i].groupby(level=0).mean() rs[i] = dfs[i].resample('h').mean() rs[i] = rs[i].fillna(0) times[i] = rs[i]['time'].tolist() if i == 1: l_1 = len(times[i]) c_l = len(times[i]) diff = l_1 - c_l if diff > 0: new_data = [0] * diff times[i] = new_data + times[i] chart.add(f"{i}", times[i], show_dots=False) i = i + 1 return chart.render_response()
Example #16
Source File: views.py From edwin with Apache License 2.0 | 4 votes |
def initValueChart(check_item, isShortTerm=True): statistics = CheckItemStatistics(check_item) if isShortTerm: data = statistics.getShortTermValueData() term_month_count = data[6] # data elements: [date_list, avg_value_list, min_value_list, max_value_list, warning_limit_list, critical_limit_list, term_month_count] title = 'Value statistics in short term(%d months)' % (term_month_count) else: data = statistics.getLongTermValueData() # data elements: [date_list, avg_value_list, min_value_list, max_value_list, warning_limit_list, critical_limit_list, term_month_count] term_month_count = data[6] title = 'Value statistics in long term(%d months)' % (term_month_count) date_list = data[0] date_list_short_format = getDatesInShortFormat(date_list) key_date_list_short_format = getDatesInShortFormat(getKeyDates(date_list)) avg_value_list = data[1] min_value_list = data[2] max_value_list = data[3] warning_limit_list = data[4] critical_limit_list = data[5] custom_style = Style(colors=( '#fd971f' # yellow--warning , '#DC3912' # red--critical , '#6c71c4' # min , '#8000FF' # max , '#00FFFF' # avg )) chart = pygal.Line(style=custom_style, legend_at_bottom=True, legend_box_size=18) SITE_ROOT = os.path.realpath(os.path.dirname(__file__)) chart.js = [os.path.join(SITE_ROOT, "static/js/", "svg.jquery.js"), os.path.join(SITE_ROOT, "static/js/", "pygal-tooltips.js")] if isShortTerm: chart.height = 420 chart.width = 900 else: chart.height = 700 chart.width = 2000 chart.disable_xml_declaration = True # disable xml root node chart.x_label_rotation = 30 chart.title = title chart.x_title = 'Timeline' chart.y_title = 'Value' chart.x_labels = map(str, date_list_short_format) chart.x_labels_major = key_date_list_short_format chart.add('Warning limit', warning_limit_list) chart.add('Critical limit', critical_limit_list) chart.add('Min value', min_value_list) chart.add('Max value', max_value_list) chart.add('Avg value', avg_value_list) return chart # http://127.0.0.1:5000/items/UNIT_TEST_NONNUMERICAL # http://127.0.0.1:5000/items/UNIT_TEST_NUMERICAL
Example #17
Source File: views.py From edwin with Apache License 2.0 | 4 votes |
def initStatusChart(check_item, isShortTerm=True): statistics = CheckItemStatistics(check_item) if isShortTerm: data = statistics.getShortTermStatusData() # data elements: [date_list, normal_list, warning_list, critical_list, term_month_count] term_month_count = data[4] title = 'Status statistics in short term(%d months)' % (term_month_count) else: data = statistics.getLongTermStatusData() # data elements: [date_list, normal_list, warning_list, critical_list, term_month_count] term_month_count = data[4] title = 'Status statistics in long term(%d months)' % (term_month_count) date_list = data[0] date_list_short_format = getDatesInShortFormat(date_list) key_date_list_short_format = getDatesInShortFormat(getKeyDates(date_list)) normal_list = data[1] warning_list = data[2] critical_list = data[3] custom_style = Style(colors=( '#b6e354' # green , '#fd971f' # yellow , '#DC3912' # red )) chart = pygal.Line(style=custom_style, legend_at_bottom=True, legend_box_size=18) SITE_ROOT = os.path.realpath(os.path.dirname(__file__)) chart.js = [os.path.join(SITE_ROOT, "static/js/", "svg.jquery.js"), os.path.join(SITE_ROOT, "static/js/", "pygal-tooltips.js")] if isShortTerm: chart.height = 420 chart.width = 900 else: chart.height = 420 chart.width = 2000 chart.disable_xml_declaration = True # disable xml root node chart.x_label_rotation = 30 chart.title = title chart.x_title = 'Timeline' chart.y_title = 'Status count' chart.x_labels = map(str, date_list_short_format) chart.x_labels_major = key_date_list_short_format chart.add('Normal count', normal_list) chart.add('Warning count', warning_list) chart.add('Critical count', critical_list) return chart
Example #18
Source File: DewpointChart.py From mvp with MIT License | 4 votes |
def buildChart(data, test=False): # Build dataframe from array df = pd.DataFrame.from_dict(data) df.set_index(['timestamp', 'name']) # Check for duplicates df = df.drop_duplicates(subset=['timestamp', 'name']) # Pivot the data by timestamp-bin with name groupings for columns df=df.pivot(index='timestamp', columns='name', values='value') if test: print df # print df # Fill missing data with dummy value df=df.fillna(11.1) #put in descending order d1=df.iloc[::-1] #pull off only 120 rows # d1 = d1[:][:120] # Reorder again d1=d1.iloc[::-1] # Make numeric (except for dates) - this does not seem to be working d1.apply(pd.to_numeric, errors='ignore') # print d1 # Calculate dew point dp=[] for idx, row in d1.iterrows(): # print row dp.append(getDewPoint(float(row['Temperature']), float(row['Humidity']))) d1['Dewpoint']=dp # Clear index so all are columns d3=d1.reset_index() if test: print d3 #build chart line_chart = pygal.Line(range=(0, 40)) line_chart.title = 'Temperature,Humidity and Dew Point' line_chart.y_title="Degrees C" line_chart.x_title="Timestamp (hover over to display date)" line_chart.x_labels = d3['timestamp'] line_chart.add('Humidity', [float(row) for row in d3['Humidity']], secondary=True) line_chart.add('Temperature',[float(row) for row in d3['Temperature']]) line_chart.add('Dewpoint', d3['Dewpoint']) line_chart.render_to_file('/home/pi/MVP/web/humidity_chart.svg')
Example #19
Source File: plotgraph.py From deeplearning-benchmark with Apache License 2.0 | 4 votes |
def main(argv): label_list = None csv_list = None try: opts, args = getopt.getopt(argv, "", ["labels=","csv=","file=","maxgpu="]) except getopt.GetoptError: print("Incorrect args") sys.exit(2) for opt, arg in opts: if opt == "--labels": label_list = arg elif opt == "--csv": csv_list = arg elif opt == "--file": out_file = arg elif opt == "--maxgpu": max_gpu = int(arg) if(label_list == None or csv_list == None or out_file == None or max_gpu == None): print("Incorrect args") sys.exit(2) labels = label_list.split(",") map(str.strip, labels) csv_files = csv_list.split(",") map(str.strip, csv_files) line_chart = pygal.Line(logarithmic=True, truncate_legend=100, legend_at_bottom=True) line_chart.title = "Deep Learning Frameworks - Performance Comparison" num_runs = math.ceil(math.log(max_gpu,2)) + 1 x = np.arange(0,num_runs) x = np.power(2,x) x[-1] = max_gpu line_chart.x_labels = map(str, x.tolist()) # Add ideal plot ideal = np.copy(x) line_chart.add('Ideal', ideal.tolist() ) index = 0 for csv_file in csv_files: with open(csv_file, mode='r') as infile: reader = csv.reader(infile, delimiter=',') baseline = 0 yval = np.empty([0]) for row in reader: if(len(row) == 2): if baseline == 0: baseline = float(row[1]) yval = np.append(yval, float(row[1])/baseline) line_chart.add(labels[index], yval.tolist(), formatter= lambda speedup, images_per_gpu=baseline: 'Speedup: %0.2f, Images/Sec: %0.2f' % (speedup, images_per_gpu*speedup)) index += 1 line_chart.render_to_file(out_file)