From e0371e4d21c5e31e36b68d0b435642aa65c76ca7 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Mon, 7 Aug 2023 17:20:18 +0200
Subject: [PATCH] Example AxesInDifferentUnits: prepare for transform at result
 level

---
 .../scatter2d/AxesInDifferentUnits.py         | 59 ++++++-------------
 .../scatter2d/AxesInDifferentUnits.py         | 59 ++++++-------------
 rawEx/scatter2d/AxesInDifferentUnits.py       | 59 ++++++-------------
 3 files changed, 51 insertions(+), 126 deletions(-)

diff --git a/auto/Examples/scatter2d/AxesInDifferentUnits.py b/auto/Examples/scatter2d/AxesInDifferentUnits.py
index 97ba2984d94..b33adec9229 100755
--- a/auto/Examples/scatter2d/AxesInDifferentUnits.py
+++ b/auto/Examples/scatter2d/AxesInDifferentUnits.py
@@ -27,52 +27,34 @@ def get_simulation(sample):
     return simulation
 
 
-def plot(result):
+def transformed_plot(i, result, title):
     """
     Plots simulation results for different detectors.
     """
-    # set plotting parameters
-    rcParams['image.aspect'] = 'auto'
-
-    plt.figure(figsize=(10, 10))
-
-    plt.subplot(2, 2, 1)
-    # default units for rectangular detector are millimeters
 
+    plt.subplot(2, 2, i)
     bp.plot_simres(result,
-                   xlabel=r'$x \;({\rm mm})$',
-                   ylabel=r'$y \;({\rm mm})$',
+                   # xlabel=r'$x \;({\rm mm})$',
+                   # ylabel=r'$y \;({\rm mm})$',
                    zlabel=None,
                    with_cb=False)
-    plt.title("Default: real-space detector coordinates", loc='left')
+    plt.title(title, loc='left')
 
-    plt.subplot(2, 2, 2)
-    bp.plot_simres(result,
-                   # units=ba.Coords_NBINS,
-                   xlabel=r'$X_{\rm bin}$',
-                   ylabel=r'$Y_{\rm bin}$',
-                   zlabel=None,
-                   with_cb=False)
-    plt.title("Bin indices", loc='left')
 
-    plt.subplot(2, 2, 3)
-    bp.plot_simres(result,
-                   # units=ba.Coords_DEGREES,
-                   xlabel=r'$\varphi_{\rm f} \;(^{\circ})$',
-                   ylabel=r'$\alpha_{\rm f} \;(^{\circ})$',
-                   zlabel=None,
-                   with_cb=False)
-    plt.title("Deflection angles", loc='left')
+if __name__ == '__main__':
+    simulation = get_simulation(get_sample())
+    result = simulation.simulate()
 
-    plt.subplot(2, 2, 4)
-    bp.plot_simres(result,
-                   # units=ba.Coords_QSPACE,
-                   xlabel=r'$Q_{y} \;(1/{\rm nm})$',
-                   ylabel=r'$Q_{z} \;(1/{\rm nm})$',
-                   zlabel=None,
-                   with_cb=False)
-    plt.title("Q space", loc='left')
+    # setup plot
+    rcParams['image.aspect'] = 'auto'
+    plt.figure(figsize=(10, 10))
+
+    transformed_plot(1, result, "Default: real-space detector coordinates")
+    transformed_plot(2, result, "Bin indices")
+    transformed_plot(3, result, "Deflection angles")
+    transformed_plot(4, result, "Q space")
 
+    # finish plot
     plt.subplots_adjust(
         left=0.07,
         right=0.97,
@@ -81,11 +63,4 @@ def plot(result):
         hspace=0.35,
         wspace=0.,
     )
-
-
-if __name__ == '__main__':
-    simulation = get_simulation(get_sample())
-    result = simulation.simulate()
-
-    plot(result)
     bp.show_or_export()
diff --git a/auto/MiniExamples/scatter2d/AxesInDifferentUnits.py b/auto/MiniExamples/scatter2d/AxesInDifferentUnits.py
index a9c9a64ab31..40bcc347b2b 100755
--- a/auto/MiniExamples/scatter2d/AxesInDifferentUnits.py
+++ b/auto/MiniExamples/scatter2d/AxesInDifferentUnits.py
@@ -27,52 +27,34 @@ def get_simulation(sample):
     return simulation
 
 
-def plot(result):
+def transformed_plot(i, result, title):
     """
     Plots simulation results for different detectors.
     """
-    # set plotting parameters
-    rcParams['image.aspect'] = 'auto'
-
-    plt.figure(figsize=(10, 10))
-
-    plt.subplot(2, 2, 1)
-    # default units for rectangular detector are millimeters
 
+    plt.subplot(2, 2, i)
     bp.plot_simres(result,
-                   xlabel=r'$x \;({\rm mm})$',
-                   ylabel=r'$y \;({\rm mm})$',
+                   # xlabel=r'$x \;({\rm mm})$',
+                   # ylabel=r'$y \;({\rm mm})$',
                    zlabel=None,
                    with_cb=False)
-    plt.title("Default: real-space detector coordinates", loc='left')
+    plt.title(title, loc='left')
 
-    plt.subplot(2, 2, 2)
-    bp.plot_simres(result,
-                   # units=ba.Coords_NBINS,
-                   xlabel=r'$X_{\rm bin}$',
-                   ylabel=r'$Y_{\rm bin}$',
-                   zlabel=None,
-                   with_cb=False)
-    plt.title("Bin indices", loc='left')
 
-    plt.subplot(2, 2, 3)
-    bp.plot_simres(result,
-                   # units=ba.Coords_DEGREES,
-                   xlabel=r'$\varphi_{\rm f} \;(^{\circ})$',
-                   ylabel=r'$\alpha_{\rm f} \;(^{\circ})$',
-                   zlabel=None,
-                   with_cb=False)
-    plt.title("Deflection angles", loc='left')
+if __name__ == '__main__':
+    simulation = get_simulation(get_sample())
+    result = simulation.simulate()
 
-    plt.subplot(2, 2, 4)
-    bp.plot_simres(result,
-                   # units=ba.Coords_QSPACE,
-                   xlabel=r'$Q_{y} \;(1/{\rm nm})$',
-                   ylabel=r'$Q_{z} \;(1/{\rm nm})$',
-                   zlabel=None,
-                   with_cb=False)
-    plt.title("Q space", loc='left')
+    # setup plot
+    rcParams['image.aspect'] = 'auto'
+    plt.figure(figsize=(10, 10))
+
+    transformed_plot(1, result, "Default: real-space detector coordinates")
+    transformed_plot(2, result, "Bin indices")
+    transformed_plot(3, result, "Deflection angles")
+    transformed_plot(4, result, "Q space")
 
+    # finish plot
     plt.subplots_adjust(
         left=0.07,
         right=0.97,
@@ -81,11 +63,4 @@ def plot(result):
         hspace=0.35,
         wspace=0.,
     )
-
-
-if __name__ == '__main__':
-    simulation = get_simulation(get_sample())
-    result = simulation.simulate()
-
-    plot(result)
     bp.show_or_export()
diff --git a/rawEx/scatter2d/AxesInDifferentUnits.py b/rawEx/scatter2d/AxesInDifferentUnits.py
index c8f1f870d93..9edfc6fb202 100755
--- a/rawEx/scatter2d/AxesInDifferentUnits.py
+++ b/rawEx/scatter2d/AxesInDifferentUnits.py
@@ -27,52 +27,34 @@ def get_simulation(sample):
     return simulation
 
 
-def plot(result):
+def transformed_plot(i, result, title):
     """
     Plots simulation results for different detectors.
     """
-    # set plotting parameters
-    rcParams['image.aspect'] = 'auto'
-
-    plt.figure(figsize=(10, 10))
-
-    plt.subplot(2, 2, 1)
-    # default units for rectangular detector are millimeters
 
+    plt.subplot(2, 2, i)
     bp.plot_simres(result,
-                   xlabel=r'$x \;({\rm mm})$',
-                   ylabel=r'$y \;({\rm mm})$',
+                   # xlabel=r'$x \;({\rm mm})$',
+                   # ylabel=r'$y \;({\rm mm})$',
                    zlabel=None,
                    with_cb=False)
-    plt.title("Default: real-space detector coordinates", loc='left')
+    plt.title(title, loc='left')
 
-    plt.subplot(2, 2, 2)
-    bp.plot_simres(result,
-                   # units=ba.Coords_NBINS,
-                   xlabel=r'$X_{\rm bin}$',
-                   ylabel=r'$Y_{\rm bin}$',
-                   zlabel=None,
-                   with_cb=False)
-    plt.title("Bin indices", loc='left')
 
-    plt.subplot(2, 2, 3)
-    bp.plot_simres(result,
-                   # units=ba.Coords_DEGREES,
-                   xlabel=r'$\varphi_{\rm f} \;(^{\circ})$',
-                   ylabel=r'$\alpha_{\rm f} \;(^{\circ})$',
-                   zlabel=None,
-                   with_cb=False)
-    plt.title("Deflection angles", loc='left')
+if __name__ == '__main__':
+    simulation = get_simulation(get_sample())
+    result = simulation.simulate()
 
-    plt.subplot(2, 2, 4)
-    bp.plot_simres(result,
-                   # units=ba.Coords_QSPACE,
-                   xlabel=r'$Q_{y} \;(1/{\rm nm})$',
-                   ylabel=r'$Q_{z} \;(1/{\rm nm})$',
-                   zlabel=None,
-                   with_cb=False)
-    plt.title("Q space", loc='left')
+    # setup plot
+    rcParams['image.aspect'] = 'auto'
+    plt.figure(figsize=(10, 10))
+
+    transformed_plot(1, result, "Default: real-space detector coordinates")
+    transformed_plot(2, result, "Bin indices")
+    transformed_plot(3, result, "Deflection angles")
+    transformed_plot(4, result, "Q space")
 
+    # finish plot
     plt.subplots_adjust(
         left=0.07,
         right=0.97,
@@ -81,11 +63,4 @@ def plot(result):
         hspace=0.35,
         wspace=0.,
     )
-
-
-if __name__ == '__main__':
-    simulation = get_simulation(get_sample())
-    result = simulation.simulate()
-
-    plot(result)
     bp.show_or_export()
-- 
GitLab