Allow to save figure directly to disk
This commit is contained in:
parent
3cdd70349e
commit
96c87a4bb6
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue