Skip to content

Commit

Permalink
Added caption and labelling options to plotting script
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephBond committed Oct 23, 2023
1 parent 6783c4d commit a4bf641
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions plot_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,33 @@
'standard': ['Trace-Eval','Trace-Bwd', 'Trace-Fwd', 'Graph-Eval', 'Graph-Bwd', 'Graph-Fwd'],
}

def parse(test_names, column_order, dest='recent.png'):
def parse(test_names, column_order, cap, lab, dest='recent.png'):
# Read benchmark csv
benchmarks = pd.read_csv('Benchmarks/benchmarks.csv', skipinitialspace=True, delimiter=',', index_col='Test-Name')

# Extract test names of interest
df = pd.DataFrame(benchmarks.loc[test_names])
df = pd.DataFrame(benchmarks.loc[test_names]).round(1)
tex = df[column_order].to_latex(float_format="%.2f", caption = cap, label = lab)
print(df[column_order])

print(tex)
# Reorder benchmark columns
# column_colors = ['#0d6b12', '#93dbb5', '#3e3875', '#b8bef5', '#910303', '#e84d4d', '#e8bceb', '#5073a1']
# Plot as bar chart
df[column_order].plot( kind="bar"
# , color=column_colors
, ylabel="Milliseconds", rot=0
, figsize=(16,6))

# Inserting a coloured horizontal line just to make clearer which columns have zero values
plt.ylim(bottom=-10)
plt.gca().axhline(0, lw=0.3, color='blue', label="Zero accuracy")
real_dest = "plots/" + dest
plt.savefig(real_dest)
plt.show()
dest_png = dest + '.png'
dest_tex = dest + '.tex'
tex_f = open(dest_tex, "w")
tex_f.write(tex)
tex_f.close()
plt.savefig(dest_png)
# plt.show()

def decompose_list(input_str):
inner = input_str.split(", ")
Expand All @@ -56,7 +61,7 @@ def bench_names(bench_str):
else:
return decompose_list(bench_str)

parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--Tests", help = "Specify list of tests")
parser.add_argument("-b", "--Benches", help = "Specify list of benchmarks to show")
parser.add_argument("-d", "--Dest", help = "Specify where to save plot")
Expand All @@ -65,7 +70,9 @@ def bench_names(bench_str):
if args.Tests and args.Benches:
tests = test_names(args.Tests)
benches = bench_names(args.Benches)
capt = "Tests: " + args.Tests + ", Benches: " + args.Benches
lab = args.Tests + '-' + args.Benches
if args.Dest:
parse(tests, benches, args.Dest)
parse(tests, benches, capt, lab, args.Dest)
else:
parse(tests, benches)
parse(tests, benches, capt, lab)

0 comments on commit a4bf641

Please sign in to comment.