Commit 22e10d5d authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[STRENGTH EVOLUTION] improve display of the text in strength display

parent 864f2e1b
No related merge requests found
Showing with 18 additions and 11 deletions
+18 -11
...@@ -233,6 +233,7 @@ class AbstractStudy(object): ...@@ -233,6 +233,7 @@ class AbstractStudy(object):
massif_name_to_color=None, massif_name_to_color=None,
show_label=True, show_label=True,
scaled=False, scaled=False,
fontsize=7,
): ):
if ax is None: if ax is None:
ax = plt.gca() ax = plt.gca()
...@@ -300,7 +301,7 @@ class AbstractStudy(object): ...@@ -300,7 +301,7 @@ class AbstractStudy(object):
massif_name = row.name massif_name = row.name
value = massif_name_to_value[massif_name] value = massif_name_to_value[massif_name]
str_value = str(value) str_value = str(value)
ax.text(x, y, str_value, horizontalalignment='center', verticalalignment='center', fontsize=7) ax.text(x, y, str_value, horizontalalignment='center', verticalalignment='center', fontsize=fontsize)
if scaled: if scaled:
plt.axis('scaled') plt.axis('scaled')
......
...@@ -105,7 +105,7 @@ class AbstractHypercubeVisualizer(object): ...@@ -105,7 +105,7 @@ class AbstractHypercubeVisualizer(object):
def study_title(self): def study_title(self):
return self.study.title return self.study.title
def show_or_save_to_file(self, specific_title='', tight=False): def show_or_save_to_file(self, specific_title='', tight=False, dpi=None):
if self.save_to_file: if self.save_to_file:
main_title, *_ = '_'.join(self.study_title.split()).split('/') main_title, *_ = '_'.join(self.study_title.split()).split('/')
filename = "{}/{}/".format(VERSION_TIME, main_title) filename = "{}/{}/".format(VERSION_TIME, main_title)
...@@ -116,6 +116,8 @@ class AbstractHypercubeVisualizer(object): ...@@ -116,6 +116,8 @@ class AbstractHypercubeVisualizer(object):
os.makedirs(dirname, exist_ok=True) os.makedirs(dirname, exist_ok=True)
if tight: if tight:
plt.savefig(filepath, bbox_inches='tight', pad_inches=-0.03, dpi=1000) plt.savefig(filepath, bbox_inches='tight', pad_inches=-0.03, dpi=1000)
elif dpi is not None:
plt.savefig(filepath, dpi=dpi)
else: else:
plt.savefig(filepath) plt.savefig(filepath)
else: else:
......
...@@ -12,6 +12,7 @@ from experiment.meteo_france_data.scm_models_data.visualization.study_visualizat ...@@ -12,6 +12,7 @@ from experiment.meteo_france_data.scm_models_data.visualization.study_visualizat
from experiment.trend_analysis.univariate_test.abstract_gev_change_point_test import AbstractGevChangePointTest from experiment.trend_analysis.univariate_test.abstract_gev_change_point_test import AbstractGevChangePointTest
from experiment.trend_analysis.univariate_test.abstract_univariate_test import AbstractUnivariateTest from experiment.trend_analysis.univariate_test.abstract_univariate_test import AbstractUnivariateTest
from extreme_estimator.margin_fits.gev.gev_params import GevParams from extreme_estimator.margin_fits.gev.gev_params import GevParams
from utils import get_display_name_from_object_type
ALTITUDES_XLABEL = 'altitudes' ALTITUDES_XLABEL = 'altitudes'
...@@ -315,7 +316,7 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer): ...@@ -315,7 +316,7 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
massif_to_year.update(massif_to_value_for_trend_type) massif_to_year.update(massif_to_value_for_trend_type)
# Compute massif_to_value # Compute massif_to_value
if self.reduce_strength_array: if self.reduce_strength_array:
massif_name_to_value = {m: "{} {}{} / {} year(s)".format( massif_name_to_value = {m: "{} {}{}".format(
int(massif_to_constant[m]), int(massif_to_constant[m]),
"+" if massif_to_strength[m] > 0 else "", "+" if massif_to_strength[m] > 0 else "",
round(massif_to_strength[m] * massif_to_constant[m], 1), round(massif_to_strength[m] * massif_to_constant[m], 1),
...@@ -325,21 +326,24 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer): ...@@ -325,21 +326,24 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
massif_name_to_value = massif_to_year massif_name_to_value = massif_to_year
self.study.visualize_study(None, massif_name_to_color=massif_to_color, show=False, self.study.visualize_study(None, massif_name_to_color=massif_to_color, show=False,
show_label=False, scaled=True, add_text=add_text, show_label=False, scaled=True, add_text=add_text,
massif_name_to_value=massif_name_to_value) massif_name_to_value=massif_name_to_value,
fontsize=4)
title = self.set_trend_test_reparition_title(subtitle, set=False) title = self.set_trend_test_reparition_title(subtitle, set=True)
# row_title = self.get_title_plot(xlabel='massifs', ax_idx=i)
# StudyVisualizer.clean_axes_write_title_on_the_left(axes_row, row_title, left_border=None)
return title return title
def set_trend_test_reparition_title(self, subtitle, set=True): def set_trend_test_reparition_title(self, subtitle, set=True):
# Global information # Global information
title = 'Repartition of {} trends'.format(subtitle) title = 'Repartition of {} trends'.format(subtitle)
title += ' at altitude={}m for the starting_year={}'.format(self.altitudes[0], self.first_starting_year) title += ' at altitude={}m \nfor the starting_year={}'.format(self.altitudes[0], self.first_starting_year)
if len(self.starting_years) > 1: if len(self.starting_years) > 1:
title += ' until starting_year={}'.format(self.last_starting_year) title += ' until starting_year={}'.format(self.last_starting_year)
title += ' with {} test'.format(get_display_name_from_object_type(self.trend_test_class))
if self.reduce_strength_array:
title += '\nEvolution of the quantile {} every {} years'.format(AbstractGevChangePointTest.quantile_for_strength,
AbstractGevChangePointTest.nb_years_for_quantile_evolution)
if set: if set:
plt.suptitle(title) plt.suptitle(title)
return title return title
...@@ -457,6 +461,6 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer): ...@@ -457,6 +461,6 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
isin_parameters=isin_parameters, isin_parameters=isin_parameters,
plot_title=plot_title) plot_title=plot_title)
if show_or_save_to_file: if show_or_save_to_file:
self.show_or_save_to_file(specific_title=last_title, tight=True) self.show_or_save_to_file(specific_title=last_title, dpi=1000)
return last_title return last_title
...@@ -16,13 +16,13 @@ def main_fast_spatial_risk_evolution(): ...@@ -16,13 +16,13 @@ def main_fast_spatial_risk_evolution():
vizualiser = get_full_altitude_visualizer(Altitude_Hypercube_Year_Visualizer, altitude=altitude, vizualiser = get_full_altitude_visualizer(Altitude_Hypercube_Year_Visualizer, altitude=altitude,
exact_starting_year=1958, reduce_strength_array=True, exact_starting_year=1958, reduce_strength_array=True,
trend_test_class=GevScaleChangePointTest) trend_test_class=GevScaleChangePointTest)
vizualiser.save_to_file = False # vizualiser.save_to_file = False
vizualiser.visualize_massif_trend_test_one_altitude() vizualiser.visualize_massif_trend_test_one_altitude()
def main_full_spatial_risk_evolution(): def main_full_spatial_risk_evolution():
for altitude in FULL_ALTITUDES[:]: for altitude in FULL_ALTITUDES[:]:
for trend_test_class in [GevLocationChangePointTest, GevScaleChangePointTest][1:]: for trend_test_class in [GevLocationChangePointTest, GevScaleChangePointTest][:]:
vizualiser = get_full_altitude_visualizer(Altitude_Hypercube_Year_Visualizer, altitude=altitude, vizualiser = get_full_altitude_visualizer(Altitude_Hypercube_Year_Visualizer, altitude=altitude,
exact_starting_year=1958, reduce_strength_array=True, exact_starting_year=1958, reduce_strength_array=True,
trend_test_class=trend_test_class) trend_test_class=trend_test_class)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment