diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-11-29 09:41:37 +0100 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-11-29 09:41:39 +0100 |
commit | dfeff57244b2d25c135a75e326140794dc4417b4 (patch) | |
tree | 0fcd2a1b013264dd5ac717638c080ca95d8e37aa /algorithms/plotter.py | |
parent | test.py: formatting fixes (diff) | |
download | sorting-algorithms-dfeff57244b2d25c135a75e326140794dc4417b4.tar.gz sorting-algorithms-dfeff57244b2d25c135a75e326140794dc4417b4.zip |
modernize plotting a bit
Use the "object-oriented" interface, fix image size, etc.
Diffstat (limited to '')
-rw-r--r-- | algorithms/plotter.py | 42 |
1 files changed, 10 insertions, 32 deletions
diff --git a/algorithms/plotter.py b/algorithms/plotter.py index 47d2929..d3e4ee4 100644 --- a/algorithms/plotter.py +++ b/algorithms/plotter.py @@ -7,41 +7,19 @@ import matplotlib.pyplot as plt class PlotBuilder: - @staticmethod - def set_xlabel(s): - plt.xlabel(s) - - @staticmethod - def set_ylabel(s): - plt.ylabel(s) + def __init__(self): + self._fig, self._ax = plt.subplots(figsize=(8, 6), dpi=200) + self._ax.grid(alpha=0.8, linestyle=':') - @staticmethod - def set_yticklabels_scientific(): - plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) - - @staticmethod - def show_grid(): - plt.grid() - - @staticmethod - def set_title(s): - plt.title(s) - - @staticmethod - def set_suptitle(s): - plt.suptitle(s) - - @staticmethod - def plot(xs, ys): - plt.plot(xs, ys) + def plot(self, title, xlabel, ylabel, xs, ys): + self._ax.set_title(title) + self._ax.set_xlabel(xlabel) + self._ax.set_ylabel(ylabel) + self._ax.plot(xs, ys) @staticmethod def show(): plt.show() - @staticmethod - def save(output_path, tight=False): - if tight: - plt.savefig(output_path, bbox_inches='tight') - else: - plt.savefig(output_path) + def save(self, output_path): + self._fig.savefig(output_path) |