Commit 6232585b authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[contrasting] improve plots. last version of the plot for the v1. improve the...

[contrasting] improve plots. last version of the plot for the v1. improve the size of the label. improve also the process to get the legend for coherence plot
parent 4b40540d
No related merge requests found
Showing with 59 additions and 38 deletions
+59 -38
...@@ -36,7 +36,7 @@ def plot_against_altitude(x_ticks, ax, massif_id, massif_name, values, altitude= ...@@ -36,7 +36,7 @@ def plot_against_altitude(x_ticks, ax, massif_id, massif_name, values, altitude=
def load_plot(cmap, graduation, label, massif_name_to_value, altitude, fit_method, add_x_label=True, def load_plot(cmap, graduation, label, massif_name_to_value, altitude, fit_method, add_x_label=True,
negative_and_positive_values=True, massif_name_to_text=None, add_colorbar=True, max_abs_change=None, negative_and_positive_values=True, massif_name_to_text=None, add_colorbar=True, max_abs_change=None,
xlabel=None): xlabel=None, fontsize_label=10):
if max_abs_change is None: if max_abs_change is None:
max_abs_change = max([abs(e) for e in massif_name_to_value.values()]) max_abs_change = max([abs(e) for e in massif_name_to_value.values()])
if negative_and_positive_values: if negative_and_positive_values:
...@@ -75,7 +75,7 @@ def load_plot(cmap, graduation, label, massif_name_to_value, altitude, fit_metho ...@@ -75,7 +75,7 @@ def load_plot(cmap, graduation, label, massif_name_to_value, altitude, fit_metho
vmax=max_ratio, vmax=max_ratio,
ticks_values_and_labels=ticks_values_and_labels, ticks_values_and_labels=ticks_values_and_labels,
label=label, label=label,
fontsize_label=10, fontsize_label=fontsize_label,
massif_name_to_text=massif_name_to_text, massif_name_to_text=massif_name_to_text,
add_text=massif_name_to_text is not None, add_text=massif_name_to_text is not None,
massif_name_to_hatch_boolean_list=massif_name_to_hatch_boolean_list massif_name_to_hatch_boolean_list=massif_name_to_hatch_boolean_list
......
...@@ -717,14 +717,15 @@ class StudyVisualizer(VisualizationParameters): ...@@ -717,14 +717,15 @@ class StudyVisualizer(VisualizationParameters):
def plot_map(self, cmap, fit_method, graduation, label, massif_name_to_value, plot_name, add_x_label=True, def plot_map(self, cmap, fit_method, graduation, label, massif_name_to_value, plot_name, add_x_label=True,
negative_and_positive_values=True, massif_name_to_text=None, altitude=None, add_colorbar=True, negative_and_positive_values=True, massif_name_to_text=None, altitude=None, add_colorbar=True,
max_abs_change=None, xlabel=None): max_abs_change=None, xlabel=None, fontsize_label=10):
if altitude is None: if altitude is None:
altitude = self.study.altitude altitude = self.study.altitude
if len(massif_name_to_value) > 0: if len(massif_name_to_value) > 0:
load_plot(cmap, graduation, label, massif_name_to_value, altitude, fitmethod_to_str(fit_method), load_plot(cmap, graduation, label, massif_name_to_value, altitude, fitmethod_to_str(fit_method),
add_x_label=add_x_label, negative_and_positive_values=negative_and_positive_values, add_x_label=add_x_label, negative_and_positive_values=negative_and_positive_values,
massif_name_to_text=massif_name_to_text, massif_name_to_text=massif_name_to_text,
add_colorbar=add_colorbar, max_abs_change=max_abs_change, xlabel=xlabel) add_colorbar=add_colorbar, max_abs_change=max_abs_change, xlabel=xlabel,
fontsize_label=fontsize_label)
self.plot_name = plot_name self.plot_name = plot_name
# self.show_or_save_to_file(add_classic_title=False, tight_layout=True, no_title=True, dpi=500) # self.show_or_save_to_file(add_classic_title=False, tight_layout=True, no_title=True, dpi=500)
self.show_or_save_to_file(add_classic_title=False, no_title=True, dpi=500, tight_layout=True) self.show_or_save_to_file(add_classic_title=False, no_title=True, dpi=500, tight_layout=True)
......
...@@ -31,8 +31,8 @@ def main(): ...@@ -31,8 +31,8 @@ def main():
massif_names = None massif_names = None
altitudes_list = altitudes_for_groups[:2] altitudes_list = altitudes_for_groups[:2]
elif fast: elif fast:
massif_names = ['Vanoise', 'Haute-Maurienne', 'Vercors'] massif_names = ['Vanoise', 'Haute-Maurienne', 'Vercors'][:1]
altitudes_list = altitudes_for_groups[:2] altitudes_list = altitudes_for_groups[2:]
else: else:
massif_names = None massif_names = None
altitudes_list = altitudes_for_groups altitudes_list = altitudes_for_groups
...@@ -55,8 +55,7 @@ def main_loop(altitudes_list, massif_names, seasons, study_classes): ...@@ -55,8 +55,7 @@ def main_loop(altitudes_list, massif_names, seasons, study_classes):
def plot_visualizers(massif_names, visualizer_list): def plot_visualizers(massif_names, visualizer_list):
# plot_histogram_all_trends_against_altitudes(massif_names, visualizer_list) plot_histogram_all_trends_against_altitudes(massif_names, visualizer_list)
# plot_histogram_all_models_against_altitudes(massif_names, visualizer_list)
# for relative in [True, False]: # for relative in [True, False]:
# plot_shoe_plot_changes_against_altitude(massif_names, visualizer_list, relative=relative) # plot_shoe_plot_changes_against_altitude(massif_names, visualizer_list, relative=relative)
# plot_coherence_curves(massif_names, visualizer_list) # plot_coherence_curves(massif_names, visualizer_list)
...@@ -65,13 +64,13 @@ def plot_visualizers(massif_names, visualizer_list): ...@@ -65,13 +64,13 @@ def plot_visualizers(massif_names, visualizer_list):
def plot_visualizer(massif_names, visualizer): def plot_visualizer(massif_names, visualizer):
# Plot time series # Plot time series
visualizer.studies.plot_maxima_time_series(massif_names=massif_names) # visualizer.studies.plot_maxima_time_series(massif_names=massif_names)
# Plot moments against altitude # Plot moments against altitude
# for std in [True, False][:]: # for std in [True, False][:]:
# for change in [True, False, None]: # for change in [True, False, None]:
# studies.plot_mean_maxima_against_altitude(massif_names=massif_names, std=std, change=change) # studies.plot_mean_maxima_against_altitude(massif_names=massif_names, std=std, change=change)
# Plot the results for the model that minimizes the individual aic # Plot the results for the model that minimizes the individual aic
# plot_individual_aic(visualizer) plot_individual_aic(visualizer)
# Plot the results for the model that minimizes the total aic # Plot the results for the model that minimizes the total aic
# plot_total_aic(model_classes, visualizer) # plot_total_aic(model_classes, visualizer)
pass pass
......
...@@ -40,12 +40,14 @@ class AbstractAltitudeGroup(object): ...@@ -40,12 +40,14 @@ class AbstractAltitudeGroup(object):
formula = 'above 3000 m' formula = 'above 3000 m'
else: else:
min_altitude, max_altitude = 1000 * i, 1000 * (i + 1) min_altitude, max_altitude = 1000 * i, 1000 * (i + 1)
formula = 'between {} m and {} m'.format(min_altitude, max_altitude) formula = 'from {} m to {} m'.format(min_altitude, max_altitude)
return formula return formula
@property @property
def formula_upper(self): def formula_upper(self):
f = self.formula f = self.formula
f = f.replace('from ', '')
f = f.replace(' to ', '-')
return f[0].upper() + f[1:] return f[0].upper() + f[1:]
......
...@@ -157,8 +157,10 @@ class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer): ...@@ -157,8 +157,10 @@ class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer):
max_abs_change = None max_abs_change = None
massif_name_to_text = None massif_name_to_text = None
graduation = self.altitude_group.graduation_for_return_level graduation = self.altitude_group.graduation_for_return_level
fontsize_label = 17
else: else:
graduation = 10 graduation = 10
fontsize_label = 10
negative_and_positive_values = self.moment_names.index(method_name) > 0 negative_and_positive_values = self.moment_names.index(method_name) > 0
# Plot the map # Plot the map
...@@ -172,6 +174,7 @@ class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer): ...@@ -172,6 +174,7 @@ class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer):
max_abs_change=max_abs_change, max_abs_change=max_abs_change,
massif_name_to_text=massif_name_to_text, massif_name_to_text=massif_name_to_text,
xlabel=self.altitude_group.xlabel, xlabel=self.altitude_group.xlabel,
fontsize_label=fontsize_label,
) )
@property @property
......
...@@ -7,47 +7,61 @@ from projects.altitude_spatial_model.altitudes_fit.one_fold_analysis.altitudes_s ...@@ -7,47 +7,61 @@ from projects.altitude_spatial_model.altitudes_fit.one_fold_analysis.altitudes_s
from projects.altitude_spatial_model.altitudes_fit.one_fold_analysis.one_fold_fit import OneFoldFit from projects.altitude_spatial_model.altitudes_fit.one_fold_analysis.one_fold_fit import OneFoldFit
def plot_coherence_curves(massif_names, visualizer_list: List[ def plot_coherence_curves(massif_names, visualizer_list: List[AltitudesStudiesVisualizerForNonStationaryModels]):
AltitudesStudiesVisualizerForNonStationaryModels]):
folder = 'Coherence' folder = 'Coherence'
visualizer = visualizer_list[0] visualizer = visualizer_list[0]
names = visualizer.get_valid_names(massif_names) names = visualizer.get_valid_names(massif_names)
all_valid_names = set.union(*[v.get_valid_names(massif_names) for v in visualizer_list]) all_valid_names = set.union(*[v.get_valid_names(massif_names) for v in visualizer_list])
for massif_name in all_valid_names: for massif_name in all_valid_names:
_, axes = plt.subplots(2, 2)
axes = axes.flatten() # For plotting the legend
legend = False
if legend:
ax = plt.gca()
axes = [ax for _ in range(4)]
else:
_, axes = plt.subplots(2, 2)
axes = axes.flatten()
for i, ax in enumerate(axes): for i, ax in enumerate(axes):
if i % 2 == 1: if i % 2 == 1:
ax.set_yticks([]) ax.set_yticks([])
axes = [ax if i % 2 == 0 else ax.twinx() for i, ax in enumerate(axes)] axes = [ax if i % 2 == 0 else ax.twinx() for i, ax in enumerate(axes)]
colors = ['blue', 'yellow', 'green'] colors = ['blue', 'yellow', 'green']
labels = ['Altitudinal-temporal model in 2019', 'Altitudinal-temporal model in 1969', 'Stationary model'] labels = ['Elevational-temporal model in 2019', 'Elevational-temporal model in 1969', 'Stationary distribution']
altitudinal_model = [True, True, False] altitudinal_model = [True, True, False]
years = [2019, 1969, None] years = [2019, 1969, None]
for color, global_label, boolean, year in list(zip(colors, labels, altitudinal_model, years))[::2]: for color, global_label, boolean, year in list(zip(colors, labels, altitudinal_model, years))[::2]:
plot_coherence_curve(axes, massif_name, visualizer_list, boolean, color, global_label, year) plot_coherence_curve(axes, massif_name, visualizer_list, boolean, color, global_label, year, legend)
visualizer.plot_name = '{}/{}'.format(folder, massif_name.replace('_', '-')) visualizer.plot_name = '{}/{}'.format(folder, massif_name.replace('_', '-'))
visualizer.show_or_save_to_file(add_classic_title=False, no_title=True, dpi=200) visualizer.show_or_save_to_file(add_classic_title=False, no_title=True, dpi=200)
plt.close() plt.close()
def plot_coherence_curve(axes, massif_name, visualizer_list: List[AltitudesStudiesVisualizerForNonStationaryModels], def plot_coherence_curve(axes, massif_name, visualizer_list: List[AltitudesStudiesVisualizerForNonStationaryModels],
is_altitudinal, color, global_label, year): is_altitudinal, color, global_label, year, legend):
x_all_list, values_all_list, labels, all_bound_list = load_all_list(massif_name, visualizer_list, is_altitudinal, x_all_list, values_all_list, labels, all_bound_list = load_all_list(massif_name, visualizer_list, is_altitudinal,
year) year)
legend_line = False
for i, label in enumerate(labels): for i, label in enumerate(labels):
if legend and i != 3:
continue
ax = axes[i] ax = axes[i]
# Plot with complete line # Plot with complete line
for j, (x_list, value_list) in enumerate(list(zip(x_all_list, values_all_list))): for j, (x_list, value_list) in enumerate(list(zip(x_all_list, values_all_list))):
value_list_i = value_list[i] value_list_i = value_list[i]
label_plot = global_label if j == 0 else None label_plot = global_label if j == 0 else None
if is_altitudinal: if is_altitudinal:
ax.plot(x_list, value_list_i, linestyle='solid', color=color) if legend and legend_line:
# ax.plot(x_list, value_list_i, linestyle='solid', color=color, label=label_plot) ax.plot(x_list, value_list_i, linestyle='solid', color=color, label=label_plot)
else:
ax.plot(x_list, value_list_i, linestyle='solid', color=color)
else: else:
# ax.plot(x_list, value_list_i, linestyle='None', color=color, label=label_plot, marker='o') if legend and legend_line:
ax.plot(x_list, value_list_i, linestyle='None', color=color, marker='o') ax.plot(x_list, value_list_i, linestyle='None', color=color, label=label_plot, marker='o')
ax.plot(x_list, value_list_i, linestyle='dotted', color=color) else:
ax.plot(x_list, value_list_i, linestyle='None', color=color, marker='o')
ax.plot(x_list, value_list_i, linestyle='dotted', color=color)
# Plot with dotted line # Plot with dotted line
for x_list_before, value_list_before, x_list_after, value_list_after in zip(x_all_list, values_all_list, for x_list_before, value_list_before, x_list_after, value_list_after in zip(x_all_list, values_all_list,
...@@ -62,18 +76,19 @@ def plot_coherence_curve(axes, massif_name, visualizer_list: List[AltitudesStudi ...@@ -62,18 +76,19 @@ def plot_coherence_curve(axes, massif_name, visualizer_list: List[AltitudesStudi
for j, (x_list, bounds) in enumerate(list(zip(x_all_list, all_bound_list))): for j, (x_list, bounds) in enumerate(list(zip(x_all_list, all_bound_list))):
if len(bounds) > 0: if len(bounds) > 0:
lower_bound, upper_bound = bounds lower_bound, upper_bound = bounds
# model_name = 'altitudinal-temporal' if is_altitudinal else 'stationary' if legend and not legend_line:
# fill_label = "95\% confidence interval for the {} model".format(model_name) if j == 0 else None model_name = 'elevational-temporal model' if is_altitudinal else 'stationary distribution'
# ax.fill_between(x_list, lower_bound, upper_bound, color=color, alpha=0.2, label=fill_label) fill_label = "95\% confidence interval for the {}".format(model_name) if j == 0 else None
ax.fill_between(x_list, lower_bound, upper_bound, color=color, alpha=0.2) ax.fill_between(x_list, lower_bound, upper_bound, color=color, alpha=0.2, label=fill_label)
else:
# if is_altitudinal: ax.fill_between(x_list, lower_bound, upper_bound, color=color, alpha=0.2)
# min, max = ax.get_ylim()
# ax.set_ylim([min, 1.5 * max]) if is_altitudinal:
# ax.legend(prop={'size': 5}) min, max = ax.get_ylim()
ax.set_ylim([min, 2 * max])
size = 17 if legend_line else 11
ax.legend(prop={'size': size})
ax.set_ylabel(label) ax.set_ylabel(label)
# if i >= 2:
# ax.set_xlabel('Altitude')
def load_all_list(massif_name, visualizer_list, altitudinal_model=True, year=2019): def load_all_list(massif_name, visualizer_list, altitudinal_model=True, year=2019):
......
...@@ -83,8 +83,8 @@ def plot_histogram_all_trends_against_altitudes(massif_names, visualizer_list: L ...@@ -83,8 +83,8 @@ def plot_histogram_all_trends_against_altitudes(massif_names, visualizer_list: L
plt.close() plt.close()
ax = plt.gca() ax = plt.gca()
width = 5 width = 5
size = 8 size = 10
legend_fontsize = 10 legend_fontsize = 15
labelsize = 10 labelsize = 10
linewidth = 3 linewidth = 3
x = np.array([3 * width * (i + 1) for i in range(len(nb_massifs))]) x = np.array([3 * width * (i + 1) for i in range(len(nb_massifs))])
...@@ -100,7 +100,7 @@ def plot_histogram_all_trends_against_altitudes(massif_names, visualizer_list: L ...@@ -100,7 +100,7 @@ def plot_histogram_all_trends_against_altitudes(massif_names, visualizer_list: L
linewidth=linewidth) linewidth=linewidth)
ax.legend(loc='upper left', prop={'size': size}) ax.legend(loc='upper left', prop={'size': size})
ax.set_ylabel('Percentage of massifs (\%) ', fontsize=legend_fontsize) ax.set_ylabel('Percentage of massifs (\%) ', fontsize=legend_fontsize)
ax.set_xlabel('Elevation', fontsize=legend_fontsize) ax.set_xlabel('Elevation group', fontsize=legend_fontsize)
ax.tick_params(axis='both', which='major', labelsize=labelsize) ax.tick_params(axis='both', which='major', labelsize=labelsize)
ax.set_xticks(x) ax.set_xticks(x)
ax.yaxis.grid() ax.yaxis.grid()
......
...@@ -89,7 +89,8 @@ class PointwiseGevStudyVisualizer(AltitudesStudies): ...@@ -89,7 +89,8 @@ class PointwiseGevStudyVisualizer(AltitudesStudies):
# Plot map of slope for each massif # Plot map of slope for each massif
visualizer = StudyVisualizer(study=self.study, show=False, save_to_file=True) visualizer = StudyVisualizer(study=self.study, show=False, save_to_file=True)
idx = 8 if param_name == GevParams.SHAPE else 1 idx = 8 if param_name == GevParams.SHAPE else 1
label = 'Elevation gradient for the {}'.format(ylabel[:-idx] + '/100m)') the = ' the' if param_name in GevParams.PARAM_NAMES else ''
label = 'Elevation gradient for{} {}'.format(the, ylabel[:-idx] + '/100m)')
gev_param_name_to_graduation = { gev_param_name_to_graduation = {
GevParams.LOC: 0.5, GevParams.LOC: 0.5,
GevParams.SCALE: 0.1, GevParams.SCALE: 0.1,
......
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