Skip to content
Snippets Groups Projects
Commit f35b1396 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

[j.748] Plot statement bp.show_or_export() or plt.show() no longer implied by...

[j.748] Plot statement bp.show_or_export() or plt.show() no longer implied by high-level plot fcts (#748) (Closes #748)

Merging branch 'j.748'  into 'main'.

See merge request !1999
parents df645987 318de085
No related branches found
No related tags found
1 merge request!1999Plot statement bp.show_or_export() or plt.show() no longer implied by high-level plot fcts (#748)
Pipeline #114108 passed
Showing
with 31 additions and 22 deletions
...@@ -8,10 +8,11 @@ BornAgain-22.0, in preparation ...@@ -8,10 +8,11 @@ BornAgain-22.0, in preparation
* SphericalDetector is obsolete. For 2D scattering, use FlatDetector as shown in examples. * SphericalDetector is obsolete. For 2D scattering, use FlatDetector as shown in examples.
* Offspec analyzer is set for detector, not scan(#651) * Offspec analyzer is set for detector, not scan(#651)
* FitObjective::addSimulationAndData has been replaced by function addFitPair, * FitObjective::addSimulationAndData has been replaced by function addFitPair,
which takes experimental data in form of a Datafield object instead of a NumPy array. which takes experimental data in form of a Datafield object instead of a NumPy array
* Function ba_plot.plot_histogram is replaced by plot_simulation_result. * Function ba_plot.plot_histogram is replaced by plot_simulation_result.
* Conversion of plot axes from default to other units now done by functions * Conversion of plot axes from default to other units now done by functions
FlatDetector::field2q, field2mm, field2angles. FlatDetector::field2q, field2mm, field2angles
* Plot statement bp.show_or_export() or plt.show() no longer implied by high-level plot fcts
> GUI changes: > GUI changes:
* Examples DepthProfile, Transmission: flattened DepthProbeSimulation * Examples DepthProfile, Transmission: flattened DepthProbeSimulation
> Examples and documentation: > Examples and documentation:
......
...@@ -440,6 +440,8 @@ def parse_args(**kwargs): ...@@ -440,6 +440,8 @@ def parse_args(**kwargs):
def show_or_export(): def show_or_export():
if do_show or figfile: # skip in test mode, saves about 0.2 s
plt.tight_layout()
if figfile: if figfile:
plt.savefig(figfile, format=saveformat, bbox_inches='tight') plt.savefig(figfile, format=saveformat, bbox_inches='tight')
if do_show: if do_show:
...@@ -462,10 +464,6 @@ def plot_simulation_result(result): ...@@ -462,10 +464,6 @@ def plot_simulation_result(result):
plot_specular_curve(result, **plotargs) plot_specular_curve(result, **plotargs)
else: else:
plot_simres(result, **plotargs) plot_simres(result, **plotargs)
if do_show or figfile: # skip in test mode, saves about 0.2 s
plt.tight_layout()
show_or_export()
def make_plot_row(results): def make_plot_row(results):
...@@ -515,13 +513,14 @@ def make_plot(results, ncol): ...@@ -515,13 +513,14 @@ def make_plot(results, ncol):
multiPlot.plot_colorlegend(im) multiPlot.plot_colorlegend(im)
show_or_export()
def plot_multicurve_specular(results):
raise Exception("Function bp.plot_multicurve_specular has become bp.plot_multicurve in BornAgain 22")
def plot_multicurve(pfields, xlabel, ylabel):
""" def plot_multicurve(results):
Plots any number of xy curves into one frame. plt.yscale('log')
""" pfields = [result.plottableField() for result in results]
if datfile: if datfile:
save_results(pfields, datfile) save_results(pfields, datfile)
...@@ -534,20 +533,11 @@ def plot_multicurve(pfields, xlabel, ylabel): ...@@ -534,20 +533,11 @@ def plot_multicurve(pfields, xlabel, ylabel):
inside_ticks() inside_ticks()
plt.xlabel(xlabel) plt.xlabel(get_axes_labels(pfields[0])[0])
plt.ylabel(ylabel) plt.ylabel(r'Intensity')
plt.legend(legend, loc=plotargs.pop('legendloc', 'upper right')) plt.legend(legend, loc=plotargs.pop('legendloc', 'upper right'))
show_or_export()
def plot_multicurve_specular(results):
plt.yscale('log')
pfields = [result.plottableField() for result in results]
xlabel = get_axes_labels(pfields[0])[0]
plot_multicurve(pfields, xlabel, r'Intensity')
# ************************************************************************** # # ************************************************************************** #
# global settings # global settings
# ************************************************************************** # # ************************************************************************** #
......
...@@ -22,3 +22,4 @@ if __name__ == '__main__': ...@@ -22,3 +22,4 @@ if __name__ == '__main__':
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -59,3 +59,4 @@ if __name__ == '__main__': ...@@ -59,3 +59,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -59,3 +59,4 @@ if __name__ == '__main__': ...@@ -59,3 +59,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -58,3 +58,4 @@ if __name__ == '__main__': ...@@ -58,3 +58,4 @@ if __name__ == '__main__':
sum = result.npArray().sum() sum = result.npArray().sum()
print(f'sum = {sum/1e9}') print(f'sum = {sum/1e9}')
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -63,3 +63,4 @@ if __name__ == '__main__': ...@@ -63,3 +63,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -70,3 +70,4 @@ if __name__ == '__main__': ...@@ -70,3 +70,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -64,3 +64,4 @@ if __name__ == '__main__': ...@@ -64,3 +64,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -33,3 +33,4 @@ if __name__ == '__main__': ...@@ -33,3 +33,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -67,3 +67,4 @@ if __name__ == '__main__': ...@@ -67,3 +67,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -60,3 +60,4 @@ if __name__ == '__main__': ...@@ -60,3 +60,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -26,3 +26,4 @@ if __name__ == '__main__': ...@@ -26,3 +26,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -40,3 +40,4 @@ if __name__ == '__main__': ...@@ -40,3 +40,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -43,3 +43,4 @@ if __name__ == '__main__': ...@@ -43,3 +43,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -54,3 +54,4 @@ if __name__ == '__main__': ...@@ -54,3 +54,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -63,3 +63,4 @@ if __name__ == '__main__': ...@@ -63,3 +63,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -88,3 +88,4 @@ if __name__ == '__main__': ...@@ -88,3 +88,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -33,3 +33,4 @@ if __name__ == '__main__': ...@@ -33,3 +33,4 @@ if __name__ == '__main__':
simulation = get_simulation(sample) simulation = get_simulation(sample)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result) bp.plot_simulation_result(result)
bp.show_or_export()
...@@ -54,3 +54,4 @@ if __name__ == '__main__': ...@@ -54,3 +54,4 @@ if __name__ == '__main__':
sample = get_sample() sample = get_sample()
simulation = get_simulation(sample) simulation = get_simulation(sample)
bp.plot_simulation_result(simulation.simulate()) bp.plot_simulation_result(simulation.simulate())
bp.show_or_export()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment