From 347ef5101ca0ad0e91c8e7ed0529b91815a5dde4 Mon Sep 17 00:00:00 2001 From: Felix Metzner <felixmetzner@outlook.com> Date: Thu, 18 Apr 2024 22:55:35 +0200 Subject: [PATCH] Adding method to export plots. --- .../dedicated_fit_approach/plotting_tools.py | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/rdstar/offline_analysis/fitting/dedicated_fit_approach/plotting_tools.py b/rdstar/offline_analysis/fitting/dedicated_fit_approach/plotting_tools.py index 20434ae1f..470f8871c 100644 --- a/rdstar/offline_analysis/fitting/dedicated_fit_approach/plotting_tools.py +++ b/rdstar/offline_analysis/fitting/dedicated_fit_approach/plotting_tools.py @@ -517,12 +517,14 @@ class SystematicsShapePlotter: yield from self.create_systematics_shape_overview_plot_for( sys_shape_info=subset_sys_shape_info, reco_ch_info=reco_channel_info, + target_dir_path=target_dir_path, ) def create_systematics_shape_overview_plot_for( self, sys_shape_info: ShapePlotInfoContainer, reco_ch_info: RecoChannelInfo, + target_dir_path: PathType, ) -> Generator[SpecificShapePlotInfoContainer, None, None]: n_eigendirs: int = sys_shape_info.number_of_eigendirections for subset_id in range(n_eigendirs): @@ -531,6 +533,7 @@ class SystematicsShapePlotter: number_of_subsets=n_eigendirs, sys_shape_info=sys_shape_info, reco_ch_info=reco_ch_info, + target_dir_path=target_dir_path, ) def _skip_this_component( @@ -559,8 +562,10 @@ class SystematicsShapePlotter: number_of_subsets: int, sys_shape_info: ShapePlotInfoContainer, reco_ch_info: RecoChannelInfo, + target_dir_path: PathType, ) -> SpecificShapePlotInfoContainer: + plot_file_name: str = f"{sys_shape_info.name}_{subset_id}" _shape_plot_infos: List[SpecificShapePlotInfoEntry] = [] n_plot_rows: int = 3 @@ -613,7 +618,7 @@ class SystematicsShapePlotter: assert normed_base_shape.shape == stat_error.shape, (normed_base_shape.shape, stat_error.shape) _shape_plot_info = SpecificShapePlotInfoEntry( - name=f"{sys_shape_info.name}_{subset_id}", + name=f"{sys_shape_info.name}_{subset_id}_{component.name}", latex_str=sys_shape_info.latex_str + f" ({subset_id})", subset_index=subset_id, normed_base_shape=normed_base_shape, @@ -638,12 +643,19 @@ class SystematicsShapePlotter: shape_plot_info=_shape_plot_info, ) - var_str: str = "" if number_of_subsets == 1 else f" ({subset_id})" - title_str: str = sys_shape_info.latex_str + f" Sys. Shape Effect{var_str} in " + reco_ch_info.latex_label - fig.suptitle(title_str, fontsize=18) - _shape_plot_infos.append(_shape_plot_info) + var_str: str = "" if number_of_subsets == 1 else f" ({subset_id})" + title_str: str = sys_shape_info.latex_str + f" Sys. Shape Effect{var_str} in " + reco_ch_info.latex_label + fig.suptitle(title_str, fontsize=18) + + export( + fig=fig, + filename=plot_file_name, + target_dir=target_dir_path, + close_figure=False, + ) + return SpecificShapePlotInfoContainer(shape_plot_infos=tuple(_shape_plot_infos)) @staticmethod @@ -682,6 +694,9 @@ class SystematicsShapePlotter: ax.set_title(shape_plot_info.component_info.latex_label, fontsize=14) + if axis_position == (0, 0): + ax.legend(frameon=False, loc=1, ncol=2, fontsize=6) + if axis_position[1] == 0: ax.set_ylabel("Relative Variations", fontsize=12) if is_last_row: -- GitLab