From 93aaf2dbc10956a02cb3551d09b07cb943985ab1 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Wed, 5 Jul 2023 18:32:41 +0200 Subject: [PATCH] simplify example PolarizedSpinAsymmetry --- .../fit/specular/PolarizedSpinAsymmetry.py | 57 +++++++++---------- .../specular/PolarizedSpinAsymmetry.py | 57 +++++++++---------- .../fit/specular/PolarizedSpinAsymmetry.py | 57 +++++++++---------- .../specular/PolarizedSpinAsymmetry.py | 57 +++++++++---------- rawEx/specular/PolarizedSpinAsymmetry.py | 57 +++++++++---------- 5 files changed, 130 insertions(+), 155 deletions(-) diff --git a/auto/Examples/fit/specular/PolarizedSpinAsymmetry.py b/auto/Examples/fit/specular/PolarizedSpinAsymmetry.py index b2f9feefbc4..d4a62cef64b 100755 --- a/auto/Examples/fit/specular/PolarizedSpinAsymmetry.py +++ b/auto/Examples/fit/specular/PolarizedSpinAsymmetry.py @@ -112,35 +112,6 @@ def qr(result): #################################################################### -def plot(qs, rs, exps, labels, filename): - """ - Plot the simulated result together with the experimental data - """ - fig = plt.figure() - ax = fig.add_subplot(111) - - for q, r, exp, l in zip(qs, rs, exps, labels): - - ax.errorbar(exp[0], - exp[1], - xerr=exp[3], - yerr=exp[2], - fmt='.', - markersize=0.75, - linewidth=0.5) - - ax.plot(q, r, label=l) - - ax.set_yscale('log') - plt.legend() - - plt.xlabel("Q [nm${}^{-1}$]") - plt.ylabel("R") - - plt.tight_layout() - plt.savefig(filename) - - def plotSpinAsymmetry(data_pp, data_mm, q, r_pp, r_mm, filename): """ Plot the simulated spin asymmetry as well its @@ -232,8 +203,32 @@ if __name__ == '__main__': data_pp = filterData(expdata_pp, qmin, qmax) data_mm = filterData(expdata_mm, qmin, qmax) - plot([q_pp, q_mm], [r_pp, r_mm], [data_pp, data_mm], ["$++$", "$--$"], - "MAFO_Saturated.pdf") + fig = plt.figure() + ax = fig.add_subplot(111) + + def plot_data(exp): + ax.errorbar(exp[0], + exp[1], + xerr=exp[3], + yerr=exp[2], + fmt='.', + markersize=0.75, + linewidth=0.5) + + plot_data(data_pp) + plot_data(data_mm) + + ax.plot(q_pp, r_pp, label="$++$") + ax.plot(q_mm, r_mm, label="$--$") + + ax.set_yscale('log') + plt.legend() + + plt.xlabel("Q [nm${}^{-1}$]") + plt.ylabel("R") + + plt.tight_layout() + # plt.savefig("MAFO_Saturated.pdf") plotSpinAsymmetry(data_pp, data_mm, qzs, r_pp, r_mm, "MAFO_Saturated_spin_asymmetry.pdf") diff --git a/auto/Examples/specular/PolarizedSpinAsymmetry.py b/auto/Examples/specular/PolarizedSpinAsymmetry.py index b2f9feefbc4..d4a62cef64b 100755 --- a/auto/Examples/specular/PolarizedSpinAsymmetry.py +++ b/auto/Examples/specular/PolarizedSpinAsymmetry.py @@ -112,35 +112,6 @@ def qr(result): #################################################################### -def plot(qs, rs, exps, labels, filename): - """ - Plot the simulated result together with the experimental data - """ - fig = plt.figure() - ax = fig.add_subplot(111) - - for q, r, exp, l in zip(qs, rs, exps, labels): - - ax.errorbar(exp[0], - exp[1], - xerr=exp[3], - yerr=exp[2], - fmt='.', - markersize=0.75, - linewidth=0.5) - - ax.plot(q, r, label=l) - - ax.set_yscale('log') - plt.legend() - - plt.xlabel("Q [nm${}^{-1}$]") - plt.ylabel("R") - - plt.tight_layout() - plt.savefig(filename) - - def plotSpinAsymmetry(data_pp, data_mm, q, r_pp, r_mm, filename): """ Plot the simulated spin asymmetry as well its @@ -232,8 +203,32 @@ if __name__ == '__main__': data_pp = filterData(expdata_pp, qmin, qmax) data_mm = filterData(expdata_mm, qmin, qmax) - plot([q_pp, q_mm], [r_pp, r_mm], [data_pp, data_mm], ["$++$", "$--$"], - "MAFO_Saturated.pdf") + fig = plt.figure() + ax = fig.add_subplot(111) + + def plot_data(exp): + ax.errorbar(exp[0], + exp[1], + xerr=exp[3], + yerr=exp[2], + fmt='.', + markersize=0.75, + linewidth=0.5) + + plot_data(data_pp) + plot_data(data_mm) + + ax.plot(q_pp, r_pp, label="$++$") + ax.plot(q_mm, r_mm, label="$--$") + + ax.set_yscale('log') + plt.legend() + + plt.xlabel("Q [nm${}^{-1}$]") + plt.ylabel("R") + + plt.tight_layout() + # plt.savefig("MAFO_Saturated.pdf") plotSpinAsymmetry(data_pp, data_mm, qzs, r_pp, r_mm, "MAFO_Saturated_spin_asymmetry.pdf") diff --git a/auto/MiniExamples/fit/specular/PolarizedSpinAsymmetry.py b/auto/MiniExamples/fit/specular/PolarizedSpinAsymmetry.py index b2f9feefbc4..d4a62cef64b 100755 --- a/auto/MiniExamples/fit/specular/PolarizedSpinAsymmetry.py +++ b/auto/MiniExamples/fit/specular/PolarizedSpinAsymmetry.py @@ -112,35 +112,6 @@ def qr(result): #################################################################### -def plot(qs, rs, exps, labels, filename): - """ - Plot the simulated result together with the experimental data - """ - fig = plt.figure() - ax = fig.add_subplot(111) - - for q, r, exp, l in zip(qs, rs, exps, labels): - - ax.errorbar(exp[0], - exp[1], - xerr=exp[3], - yerr=exp[2], - fmt='.', - markersize=0.75, - linewidth=0.5) - - ax.plot(q, r, label=l) - - ax.set_yscale('log') - plt.legend() - - plt.xlabel("Q [nm${}^{-1}$]") - plt.ylabel("R") - - plt.tight_layout() - plt.savefig(filename) - - def plotSpinAsymmetry(data_pp, data_mm, q, r_pp, r_mm, filename): """ Plot the simulated spin asymmetry as well its @@ -232,8 +203,32 @@ if __name__ == '__main__': data_pp = filterData(expdata_pp, qmin, qmax) data_mm = filterData(expdata_mm, qmin, qmax) - plot([q_pp, q_mm], [r_pp, r_mm], [data_pp, data_mm], ["$++$", "$--$"], - "MAFO_Saturated.pdf") + fig = plt.figure() + ax = fig.add_subplot(111) + + def plot_data(exp): + ax.errorbar(exp[0], + exp[1], + xerr=exp[3], + yerr=exp[2], + fmt='.', + markersize=0.75, + linewidth=0.5) + + plot_data(data_pp) + plot_data(data_mm) + + ax.plot(q_pp, r_pp, label="$++$") + ax.plot(q_mm, r_mm, label="$--$") + + ax.set_yscale('log') + plt.legend() + + plt.xlabel("Q [nm${}^{-1}$]") + plt.ylabel("R") + + plt.tight_layout() + # plt.savefig("MAFO_Saturated.pdf") plotSpinAsymmetry(data_pp, data_mm, qzs, r_pp, r_mm, "MAFO_Saturated_spin_asymmetry.pdf") diff --git a/auto/MiniExamples/specular/PolarizedSpinAsymmetry.py b/auto/MiniExamples/specular/PolarizedSpinAsymmetry.py index b2f9feefbc4..d4a62cef64b 100755 --- a/auto/MiniExamples/specular/PolarizedSpinAsymmetry.py +++ b/auto/MiniExamples/specular/PolarizedSpinAsymmetry.py @@ -112,35 +112,6 @@ def qr(result): #################################################################### -def plot(qs, rs, exps, labels, filename): - """ - Plot the simulated result together with the experimental data - """ - fig = plt.figure() - ax = fig.add_subplot(111) - - for q, r, exp, l in zip(qs, rs, exps, labels): - - ax.errorbar(exp[0], - exp[1], - xerr=exp[3], - yerr=exp[2], - fmt='.', - markersize=0.75, - linewidth=0.5) - - ax.plot(q, r, label=l) - - ax.set_yscale('log') - plt.legend() - - plt.xlabel("Q [nm${}^{-1}$]") - plt.ylabel("R") - - plt.tight_layout() - plt.savefig(filename) - - def plotSpinAsymmetry(data_pp, data_mm, q, r_pp, r_mm, filename): """ Plot the simulated spin asymmetry as well its @@ -232,8 +203,32 @@ if __name__ == '__main__': data_pp = filterData(expdata_pp, qmin, qmax) data_mm = filterData(expdata_mm, qmin, qmax) - plot([q_pp, q_mm], [r_pp, r_mm], [data_pp, data_mm], ["$++$", "$--$"], - "MAFO_Saturated.pdf") + fig = plt.figure() + ax = fig.add_subplot(111) + + def plot_data(exp): + ax.errorbar(exp[0], + exp[1], + xerr=exp[3], + yerr=exp[2], + fmt='.', + markersize=0.75, + linewidth=0.5) + + plot_data(data_pp) + plot_data(data_mm) + + ax.plot(q_pp, r_pp, label="$++$") + ax.plot(q_mm, r_mm, label="$--$") + + ax.set_yscale('log') + plt.legend() + + plt.xlabel("Q [nm${}^{-1}$]") + plt.ylabel("R") + + plt.tight_layout() + # plt.savefig("MAFO_Saturated.pdf") plotSpinAsymmetry(data_pp, data_mm, qzs, r_pp, r_mm, "MAFO_Saturated_spin_asymmetry.pdf") diff --git a/rawEx/specular/PolarizedSpinAsymmetry.py b/rawEx/specular/PolarizedSpinAsymmetry.py index b2f9feefbc4..d4a62cef64b 100755 --- a/rawEx/specular/PolarizedSpinAsymmetry.py +++ b/rawEx/specular/PolarizedSpinAsymmetry.py @@ -112,35 +112,6 @@ def qr(result): #################################################################### -def plot(qs, rs, exps, labels, filename): - """ - Plot the simulated result together with the experimental data - """ - fig = plt.figure() - ax = fig.add_subplot(111) - - for q, r, exp, l in zip(qs, rs, exps, labels): - - ax.errorbar(exp[0], - exp[1], - xerr=exp[3], - yerr=exp[2], - fmt='.', - markersize=0.75, - linewidth=0.5) - - ax.plot(q, r, label=l) - - ax.set_yscale('log') - plt.legend() - - plt.xlabel("Q [nm${}^{-1}$]") - plt.ylabel("R") - - plt.tight_layout() - plt.savefig(filename) - - def plotSpinAsymmetry(data_pp, data_mm, q, r_pp, r_mm, filename): """ Plot the simulated spin asymmetry as well its @@ -232,8 +203,32 @@ if __name__ == '__main__': data_pp = filterData(expdata_pp, qmin, qmax) data_mm = filterData(expdata_mm, qmin, qmax) - plot([q_pp, q_mm], [r_pp, r_mm], [data_pp, data_mm], ["$++$", "$--$"], - "MAFO_Saturated.pdf") + fig = plt.figure() + ax = fig.add_subplot(111) + + def plot_data(exp): + ax.errorbar(exp[0], + exp[1], + xerr=exp[3], + yerr=exp[2], + fmt='.', + markersize=0.75, + linewidth=0.5) + + plot_data(data_pp) + plot_data(data_mm) + + ax.plot(q_pp, r_pp, label="$++$") + ax.plot(q_mm, r_mm, label="$--$") + + ax.set_yscale('log') + plt.legend() + + plt.xlabel("Q [nm${}^{-1}$]") + plt.ylabel("R") + + plt.tight_layout() + # plt.savefig("MAFO_Saturated.pdf") plotSpinAsymmetry(data_pp, data_mm, qzs, r_pp, r_mm, "MAFO_Saturated_spin_asymmetry.pdf") -- GitLab