diff --git a/Examples/Python/sim03_Structures/FindPeaks.py b/Examples/Python/sim03_Structures/FindPeaks.py
index 73d5d3cc323d699c82bce0a2d72721adc9d43647..2ec3cf1487c105693f9d770eceb3fe3c993c7337 100644
--- a/Examples/Python/sim03_Structures/FindPeaks.py
+++ b/Examples/Python/sim03_Structures/FindPeaks.py
@@ -77,7 +77,7 @@ def run_simulation():
     return simulation.result()
 
 
-if __name__ == '__main__':
+def simulate_and_plot():
     result = run_simulation().histogram2d()
     ba.plot_histogram(result, cmap='jet', aspect='auto')
 
@@ -92,3 +92,7 @@ if __name__ == '__main__':
              color='white',
              markersize=10)
     plt.show()
+
+
+if __name__ == '__main__':
+    simulate_and_plot()
diff --git a/Examples/Python/sim04_Multilayers/GratingMC.py b/Examples/Python/sim04_Multilayers/GratingMC.py
index 91cb58dfa3f6c1264b57abec931f3bc151e8ae57..8e1a89e89f7f2644940cc15419410cab96a34dd0 100644
--- a/Examples/Python/sim04_Multilayers/GratingMC.py
+++ b/Examples/Python/sim04_Multilayers/GratingMC.py
@@ -77,7 +77,7 @@ def run_simulation():
     return simulation.result()
 
 
-if __name__ == '__main__':
+def simulate_and_plot():
     interactive = True
     result = run_simulation().histogram2d()
     ba.plot_histogram(result, cmap='jet', aspect='auto')
@@ -93,3 +93,7 @@ if __name__ == '__main__':
              color='white',
              markersize=10)
     plt.show()
+
+
+if __name__ == '__main__':
+    simulate_and_plot()