You've already forked etude_lego_jurassic_world
Réorganise les visuels de l'étape 15 sous figures/step15
This commit is contained in:
@@ -79,11 +79,21 @@ def build_heatmap_data(rows: Iterable[dict]) -> Tuple[List[int], List[str], np.n
|
||||
return years, labels, matrix, swatches
|
||||
|
||||
|
||||
def plot_colors_heatmap(matrix_path: Path, destination_path: Path, use_log_scale: bool = False) -> None:
|
||||
"""Génère une heatmap année × couleur basée sur les quantités totales avec pastilles."""
|
||||
def plot_colors_heatmap(
|
||||
matrix_path: Path,
|
||||
destination_path: Path,
|
||||
use_log_scale: bool = False,
|
||||
normalize_by_year: bool = False,
|
||||
) -> None:
|
||||
"""Génère une heatmap année × couleur avec pastilles (linéaire, log1p ou normalisée)."""
|
||||
rows = load_rows(matrix_path)
|
||||
years, labels, matrix, swatches = build_heatmap_data(rows)
|
||||
values = np.log1p(matrix) if use_log_scale else matrix
|
||||
values = matrix
|
||||
if normalize_by_year:
|
||||
column_totals = matrix.sum(axis=0, keepdims=True)
|
||||
values = matrix / column_totals
|
||||
if use_log_scale:
|
||||
values = np.log1p(values)
|
||||
|
||||
fig, ax = plt.subplots(figsize=(14, max(6, len(labels) * 0.26)))
|
||||
y_positions = np.arange(len(labels))
|
||||
@@ -108,10 +118,18 @@ def plot_colors_heatmap(matrix_path: Path, destination_path: Path, use_log_scale
|
||||
)
|
||||
ax.set_xlim(-1.1, len(years) - 0.5)
|
||||
ax.set_xlabel("Année")
|
||||
title_scale = "log1p des quantités" if use_log_scale else "quantités totales"
|
||||
if normalize_by_year:
|
||||
title_scale = "parts de couleur (par année)"
|
||||
else:
|
||||
title_scale = "log1p des quantités" if use_log_scale else "quantités totales"
|
||||
ax.set_title(f"Intensité des couleurs par année ({title_scale})")
|
||||
cbar = fig.colorbar(heatmap, ax=ax, shrink=0.82, pad=0.018)
|
||||
cbar_label = "log1p(quantité totale)" if use_log_scale else "quantité totale"
|
||||
if normalize_by_year:
|
||||
cbar_label = "Part de la couleur (0-1)"
|
||||
elif use_log_scale:
|
||||
cbar_label = "log1p(quantité totale)"
|
||||
else:
|
||||
cbar_label = "quantité totale"
|
||||
cbar.set_label(cbar_label)
|
||||
ensure_parent_dir(destination_path)
|
||||
fig.subplots_adjust(left=0.26, right=0.97, bottom=0.08, top=0.94)
|
||||
|
||||
Reference in New Issue
Block a user