From f662f7b91a63104252b5f1895d306946a989f59e Mon Sep 17 00:00:00 2001 From: Le Roux Erwan <erwan.le-roux@irstea.fr> Date: Thu, 28 Feb 2019 15:02:37 +0100 Subject: [PATCH] [SCM] fix vertical plot of kde to take into acccount latest improvement --- experiment/meteo_france_SCM_study/abstract_study.py | 8 ++++---- experiment/meteo_france_SCM_study/main_visualize.py | 6 +++--- .../meteo_france_SCM_study/safran/safran_visualizer.py | 10 +++++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/experiment/meteo_france_SCM_study/abstract_study.py b/experiment/meteo_france_SCM_study/abstract_study.py index c47ee107..82c6dc5c 100644 --- a/experiment/meteo_france_SCM_study/abstract_study.py +++ b/experiment/meteo_france_SCM_study/abstract_study.py @@ -19,13 +19,13 @@ from utils import get_full_path, cached_property class AbstractStudy(object): ALTITUDES = [1800, 2400] - def __init__(self, variable_class, altitude=1800): + def __init__(self, variable_class: type, altitude: int = 1800): assert altitude in self.ALTITUDES self.altitude = altitude self.model_name = None self.variable_class = variable_class - def write_to_file(self, df): + def write_to_file(self, df: pd.DataFrame): if not op.exists(self.result_full_path): os.makedirs(self.result_full_path, exist_ok=True) df.to_csv(op.join(self.result_full_path, 'merged_array_{}_altitude.csv'.format(self.altitude))) @@ -82,7 +82,7 @@ class AbstractStudy(object): return year_to_daily_time_serie @property - def _year_to_max_daily_time_serie(self): + def _year_to_max_daily_time_serie(self) -> OrderedDict: return self._year_to_daily_time_serie ########## @@ -92,7 +92,7 @@ class AbstractStudy(object): return self.original_safran_massif_names @property - def original_safran_massif_names(self): + def original_safran_massif_names(self) -> List[str]: # Load the names of the massif as defined by SAFRAN return safran_massif_names_from_datasets(list(self.year_to_dataset_ordered_dict.values()), self.altitude) diff --git a/experiment/meteo_france_SCM_study/main_visualize.py b/experiment/meteo_france_SCM_study/main_visualize.py index 6dba3107..f425c927 100644 --- a/experiment/meteo_france_SCM_study/main_visualize.py +++ b/experiment/meteo_france_SCM_study/main_visualize.py @@ -34,10 +34,10 @@ def study_iterator(study_class, only_first_one=False, both_altitude=False, verbo def extended_visualization(): save_to_file = True - only_first_one = False - for study_class in SCM_EXTENDED_STUDIES[:]: + only_first_one = True + for study_class in SCM_EXTENDED_STUDIES[:1]: for study in study_iterator(study_class, only_first_one=only_first_one): - study_visualizer = StudyVisualizer(study, save_to_file=save_to_file, only_one_graph=True) + study_visualizer = StudyVisualizer(study, save_to_file=save_to_file, only_one_graph=True, year_for_kde_plot=1958, vertical_kde_plot=True) # study_visualizer.visualize_all_mean_and_max_graphs() study_visualizer.visualize_all_experimental_law() # for study_class in SCM_EXTENDED_STUDIES[:]: diff --git a/experiment/meteo_france_SCM_study/safran/safran_visualizer.py b/experiment/meteo_france_SCM_study/safran/safran_visualizer.py index 1f5b1802..33ad8268 100644 --- a/experiment/meteo_france_SCM_study/safran/safran_visualizer.py +++ b/experiment/meteo_france_SCM_study/safran/safran_visualizer.py @@ -102,10 +102,14 @@ class StudyVisualizer(object): all_massif_data = np.sort(all_massif_data) # Display an histogram on the background (with 100 bins, for visibility, and to check 0.9 quantiles) - ax2 = ax.twinx() + ax2 = ax.twiny() if self.vertical_kde_plot else ax.twinx() color_hist = 'k' - ax2.hist(all_massif_data, bins=50, density=True, histtype='step', color=color_hist) - ax2.set_ylabel('normalized histogram', color=color_hist) + orientation = "horizontal" if self.vertical_kde_plot else 'vertical' + ax2.hist(all_massif_data, bins=50, density=True, histtype='step', color=color_hist, orientation=orientation) + label_function = ax2.set_xlabel if self.vertical_kde_plot else ax2.set_ylabel + # Do not display this label in the vertical plot + if not self.vertical_kde_plot: + label_function('normalized histogram', color=color_hist) # Kde plot, and retrieve the data forming the line color_kde = 'b' -- GitLab