示例#1
0
def main():
    if not os.path.isdir(GRAPH_DIR):
        os.mkdir(GRAPH_DIR)

    PARSER = argparse.ArgumentParser(description='Produces a graph for display with dzen2')
    PARSER.add_argument('name', type=str, help='unique identifier for graph')
    PARSER.add_argument('points', type=float, nargs='+',
                    help='')
    PARSER.add_argument('--area', '-A', action='store_true', default=False,
                    help='Fill in the area under the graph')
    args = PARSER.parse_args()

    graph = tinygraph.tiny_graph(20, args.points, point_size=4, area=args.area)
    filename = os.path.join(GRAPH_DIR, args.name + '.xpm')
    with open(filename, 'w') as f:
        f.write(xpm.pil_save(graph.image))

    print "^i({})".format(filename)
示例#2
0

if __name__ == '__main__':
    PARSER = argparse.ArgumentParser(description='''Draw a tiny graph. Supports XPM well because several tools seem to use this.''')
    PARSER.add_argument('values', type=float, nargs='+',
                       help='values')
    PARSER.add_argument('-o', '--output', type=str,
        help='where to save file')
    PARSER.add_argument('-p', '--point-size', type=int,
        help='how big rendered poitns should be', default=1)
    PARSER.add_argument('-H', '--height', type=int,
        help='height of image in pixels', default=10)
    PARSER.add_argument('-f', '--format', type=str,
        help='what format to save in', default=None)
    args = PARSER.parse_args()
    graph = tiny_graph(args.height, args.values, point_size=args.point_size)

    if args.output is None:
        if args.format is None:
            print xpm.pil_save(graph.image)
        elif args.format.lower() == 'xpm':
            graph.save(sys.stdout, args.format)
        else:
            graph.save(sys.stdout, args.format)
    elif args.format.lower() == 'xpm' or args.output.endswith('.xpm'):
        # Pil cannot write xpm at the moment
        with open(args.output, 'w') as f:
            f.write(xpm.pil_save(graph.image))
    else:
        graph.save(args.output, args.format)