diff options
author | Birte Kristina Friesel <birte.friesel@uos.de> | 2023-12-11 13:37:39 +0100 |
---|---|---|
committer | Birte Kristina Friesel <birte.friesel@uos.de> | 2023-12-11 13:37:39 +0100 |
commit | b2b5edfc75898517fd70ece498752a61513ab618 (patch) | |
tree | d19dce055a9995f61a04ef8fc3f8f3aae183f358 /lib | |
parent | 0a90f760c6f9ec573297672444a1706b33bc9108 (diff) |
plotter: export and interactive visualization are no longer mutually exclusive
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() |