diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2020-02-11 12:38:00 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2020-02-11 12:38:00 +0100 |
| commit | 9e2d7eb1cb952b398bd7363ab95ea9f1d4598ab1 (patch) | |
| tree | 03330c63b7b491b8e1bd7e675a66c37bf2c23ac9 | |
| parent | 3fd6859acb4aacec84e8eba8c30f11fa6edb265c (diff) | |
| download | allocbench-9e2d7eb1cb952b398bd7363ab95ea9f1d4598ab1.tar.gz allocbench-9e2d7eb1cb952b398bd7363ab95ea9f1d4598ab1.zip | |
implement standalone pgfplot legend creation
| -rw-r--r-- | src/benchmark.py | 52 | ||||
| -rw-r--r-- | src/benchmarks/loop.py | 3 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/benchmark.py b/src/benchmark.py index 29442d1..fd094d0 100644 --- a/src/benchmark.py +++ b/src/benchmark.py @@ -975,6 +975,58 @@ class Benchmark: print("\\end{tabular}", file=f) print("\\end{document}", file=f) + def pgfplot_legend(self, sumdir=""): + + allocators = self.results["allocators"] + s =\ +""" +\\documentclass{standalone} +\\usepackage{pgfplots} + +\\usepackage{pgfkeys} + +\\newenvironment{customlegend}[1][]{% +\t\\begingroup +\t\\csname pgfplots@init@cleared@structures\\endcsname +\t\\pgfplotsset{#1}% +}{% +\t\\csname pgfplots@createlegend\\endcsname +\t\\endgroup +}% +\\def\\addlegendimage{\\csname pgfplots@addlegendimage\\endcsname} + +\\usepackage{xcolor} +""" + + for alloc_name, alloc_dict in allocators.items(): + # define color + rgb = matplotlib.colors.to_rgb(alloc_dict["color"]) + s += f"\\providecolor{{{alloc_name}-color}}{{rgb}}{{{rgb[0]},{rgb[1]},{rgb[2]}}}\n" + + s +=\ +""" +\\begin{document} +\\begin{tikzpicture} +\\begin{customlegend}[ +\tlegend entries={""" + + alloc_list = "" + addlegendimage_list = "" + for alloc_name in allocators: + alloc_list += f"{alloc_name}, " + addlegendimage_list += "\t\\addlegendimage{}\n" + + s += alloc_list[:-2] + "},\n]" + s += addlegendimage_list + s +=\ +""" +\\end{customlegend} +\\end{tikzpicture} +\\end{document}""" + + with open(os.path.join(sumdir, "legend.tex"), "w") as legend_file: + print(s, file=legend_file) + def pgfplot_linear(self, perms, xval, yval, ylabel="'y-label'", xlabel="'x-label'", title="'default title'", postfix="", sumdir="", scale=None): diff --git a/src/benchmarks/loop.py b/src/benchmarks/loop.py index b0c3929..a969f4a 100644 --- a/src/benchmarks/loop.py +++ b/src/benchmarks/loop.py @@ -94,4 +94,7 @@ class BenchmarkLoop(Benchmark): title='"Loop: 1024B"', postfix='mops_1024B') + # create pgfplot legend + self.pgfplot_legend() + loop = BenchmarkLoop() |
