diff options
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/plotter.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/plotter.py b/lib/plotter.py index f0debee..7ec96b3 100755 --- a/lib/plotter.py +++ b/lib/plotter.py @@ -124,7 +124,9 @@ def plot_y(Y, **kwargs): plot_xy(np.arange(len(Y)), Y, **kwargs) -def plot_xy(X, Y, xlabel=None, ylabel=None, title=None, output=None, family=False): +def plot_xy( + X, Y, xlabel=None, ylabel=None, title=None, output=None, family=False, show=True +): fig, ax1 = plt.subplots(figsize=(10, 6)) if title is not None: ax1.set_title(title) @@ -145,14 +147,17 @@ def plot_xy(X, Y, xlabel=None, ylabel=None, title=None, output=None, family=Fals plt.plot(X, Y, "bo", markersize=2) if output: plt.savefig(output) + print(f"plot saved to {output}") with open("{}.txt".format(output), "w") as f: print("X Y", file=f) for i in range(len(X)): print("{} {}".format(X[i], Y[i]), file=f) - print(f"plot saved to {output}") - else: + print(f"data saved to {output}.txt") + if show: plt.show() + plt.close() + def _param_slice_eq(a, b, index): return (*a[1][:index], *a[1][index + 1 :]) == ( @@ -171,6 +176,7 @@ def plot_param( title=None, extra_function=None, output=None, + show=True, ): fig, ax1 = plt.subplots(figsize=(10, 6)) if title is not None: @@ -270,9 +276,11 @@ def plot_param( if output: plt.savefig(output) print(f"plot saved to {output}") - else: + if show: plt.show() + plt.close() + def plot_param_fit( function, @@ -330,7 +338,9 @@ def plot_param_fit( plt.show() -def boxplot(ticks, measurements, xlabel="", ylabel="", modeldata=None, output=None): +def boxplot( + ticks, measurements, xlabel="", ylabel="", modeldata=None, output=None, show=True +): fig, ax1 = plt.subplots(figsize=(10, 6)) ax1.set_title(f"dfatool unparam (n={len(measurements[0])})") plt.subplots_adjust(left=0.1, right=0.95, top=0.95, bottom=0.1) @@ -412,13 +422,14 @@ def boxplot(ticks, measurements, xlabel="", ylabel="", modeldata=None, output=No if output: plt.savefig(output) + print(f"plot saved to {output}") with open("{}.txt".format(output), "w") as f: print("X Y", file=f) for i, data in enumerate(measurements): for value in data: print("{} {}".format(ticks[i], value), file=f) - print(f"plot saved to {output}") - else: + print(f"data saved to {output}.txt") + if show: plt.show() plt.close() |