Allow to save figure directly to disk

This commit is contained in:
Lucas De Marchi 2013-08-16 01:07:18 -03:00
parent 3cdd70349e
commit 96c87a4bb6
2 changed files with 20 additions and 4 deletions

View File

@ -2,6 +2,8 @@
import sys
import os.path
import argparse
def parse_table(f):
curr = 0
@ -37,8 +39,14 @@ def add_at(ax, t, loc=2):
return _at
parser = argparse.ArgumentParser()
parser.add_argument('--save', action='store_true')
parser.add_argument('files', nargs='*')
args = parser.parse_args()
figs = []
for fn in sys.argv[1:]:
for fn in args.files:
fig = plt.figure()
figs += [fig]
@ -62,5 +70,8 @@ for fn in sys.argv[1:]:
fig.tight_layout()
fig.subplots_adjust(top=0.9)
plt.show()
if args.save:
for fig, fn in zip(figs, args.files):
fig.savefig(os.path.splitext(fn)[0] + '.png')
else:
plt.show()

View File

@ -23,6 +23,7 @@ def parse_table(f):
parser = argparse.ArgumentParser()
parser.add_argument('--name', type=str, default='')
parser.add_argument('--save', action='store_true')
parser.add_argument('file', nargs='*')
args = parser.parse_args()
@ -44,4 +45,8 @@ fig.suptitle('Hash function timings: %s' % args.name, weight='bold',
size='large')
fig.tight_layout()
plt.subplots_adjust(top=0.9)
plt.show()
if args.save:
fig.savefig(os.path.dirname(args.file[0]) + '/plot.png')
else:
plt.show()