From 0a60bb09e93d442fd74d3f4fe869a4c590347909 Mon Sep 17 00:00:00 2001 From: Pim Nelissen Date: Mon, 30 Mar 2026 08:23:02 +0200 Subject: [PATCH] improve plotting functionality --- src/pg_rad/plotting/landscape_plotter.py | 7 +------ src/pg_rad/plotting/result_plotter.py | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/pg_rad/plotting/landscape_plotter.py b/src/pg_rad/plotting/landscape_plotter.py index aebfc36..80d3020 100644 --- a/src/pg_rad/plotting/landscape_plotter.py +++ b/src/pg_rad/plotting/landscape_plotter.py @@ -58,12 +58,7 @@ class LandscapeSlicePlotter: ax.set_xlim(right=max(width, .5*height)) # if the road is very flat, we center it vertically (looks better) - if median(landscape.path.y_list) == 0: - h = max(height, .5*width) - ax.set_ylim(bottom=-h//2, - top=h//2) - else: - ax.set_ylim(top=max(height, .5*width)) + ax.set_ylim(bottom=-.5*width, top=.5*width) ax.set_xlabel("X [m]") ax.set_ylabel("Y [m]") diff --git a/src/pg_rad/plotting/result_plotter.py b/src/pg_rad/plotting/result_plotter.py index c7cd323..265aa7d 100644 --- a/src/pg_rad/plotting/result_plotter.py +++ b/src/pg_rad/plotting/result_plotter.py @@ -37,7 +37,7 @@ class ResultPlotter: self._draw_cps(ax_cps) ax_counts = fig.add_subplot(gs[0, 1]) - self._draw_count_rate(ax_counts) + self._draw_counts(ax_counts) ax_landscape = fig.add_subplot(gs[1, :]) self._plot_landscape(ax_landscape, landscape_z) @@ -77,15 +77,20 @@ class ResultPlotter: def _draw_cps(self, ax): x = self.count_rate_res.sub_points y = self.count_rate_res.cps - ax.plot(x, y, color='b') + ax.plot(x, y, color='b', label=f'max(CPS) = {y.max():.2f}') + ax.legend(handlelength=0, handletextpad=0, fancybox=True) ax.set_title('Counts per second (CPS)') ax.set_xlabel('Arc length s [m]') ax.set_ylabel('CPS [s$^{-1}$]') - def _draw_count_rate(self, ax): - x = self.count_rate_res.acquisition_points - y = self.count_rate_res.integrated_counts - ax.plot(x, y, color='r', linestyle='--', alpha=0.2) + def _draw_counts(self, ax): + x = self.count_rate_res.acquisition_points[1:] + y = self.count_rate_res.integrated_counts[1:] + ax.plot( + x, y, color='r', linestyle='--', + alpha=0.2, label=f'max(counts) = {y.max():.2f}' + ) + ax.legend(handlelength=0, handletextpad=0, fancybox=True) ax.scatter(x, y, color='r', marker='x') ax.set_title('Integrated counts') ax.set_xlabel('Arc length s [m]') @@ -99,6 +104,7 @@ class ResultPlotter: ["Air density (kg/m^3)", round(self.landscape.air_density, 3)], ["Total path length (m)", round(self.landscape.path.length, 3)], ["Readout points", len(self.count_rate_res.integrated_counts)], + ["Mean background cps", round(self.count_rate_res.mean_bkg_cps, 3)] ] ax.table( @@ -124,7 +130,7 @@ class ResultPlotter: # list field efficiencies for each primary gamma in the landscape effs = {e: det.get_efficiency(e) for e in source_energies} formatted_effs = ", ".join( - f"{value:.3f} @ {key:.1f} keV" + f"{value:.5f} @ {key:.1f} keV" for key, value in effs.items() ) ax.set_axis_off() @@ -201,6 +207,5 @@ class ResultPlotter: theta_rad = np.radians(theta_deg) - print(theta_rad) ax.plot(theta_rad, eff) ax.set_title(f"Rel. angular efficiency @ {energy_keV:.1f} keV")