You've already forked etude_lego_jurassic_world
Chiffre les personnages par année avec heatmap
This commit is contained in:
@@ -48,7 +48,7 @@ def plot_minifigs_per_character(counts_path: Path, destination_path: Path) -> No
|
||||
|
||||
|
||||
def plot_character_year_presence(presence_path: Path, destination_path: Path) -> None:
|
||||
"""Trace une heatmap binaire indiquant la présence d'un personnage par année."""
|
||||
"""Trace une heatmap indiquant le nombre de minifigs par personnage et par année."""
|
||||
rows = load_presence(presence_path)
|
||||
if not rows:
|
||||
return
|
||||
@@ -56,7 +56,7 @@ def plot_character_year_presence(presence_path: Path, destination_path: Path) ->
|
||||
characters = sorted(
|
||||
{row["known_character"] for row in rows},
|
||||
key=lambda name: (
|
||||
-sum(1 for r in rows if r["known_character"] == name and r["present"] == "1"),
|
||||
-sum(int(r["minifig_count"]) for r in rows if r["known_character"] == name),
|
||||
name,
|
||||
),
|
||||
)
|
||||
@@ -64,11 +64,11 @@ def plot_character_year_presence(presence_path: Path, destination_path: Path) ->
|
||||
for character in characters:
|
||||
row_values = []
|
||||
for year in years:
|
||||
present = next(
|
||||
(r["present"] for r in rows if r["known_character"] == character and int(r["year"]) == year),
|
||||
count = next(
|
||||
(r["minifig_count"] for r in rows if r["known_character"] == character and int(r["year"]) == year),
|
||||
"0",
|
||||
)
|
||||
row_values.append(int(present))
|
||||
row_values.append(int(count))
|
||||
matrix.append(row_values)
|
||||
|
||||
height = max(5, len(characters) * 0.35)
|
||||
@@ -80,13 +80,15 @@ def plot_character_year_presence(presence_path: Path, destination_path: Path) ->
|
||||
ax.set_yticklabels(characters)
|
||||
ax.set_xlabel("Année")
|
||||
ax.set_ylabel("Personnage")
|
||||
ax.set_title("Présence des personnages par année (hors figurants)")
|
||||
ax.set_title("Nombre de minifigs par personnage et par année (hors figurants)")
|
||||
for i, character in enumerate(characters):
|
||||
for j, year in enumerate(years):
|
||||
value = matrix[i][j]
|
||||
if value == 1:
|
||||
ax.text(j, i, "●", ha="center", va="center", color="#0d0d0d", fontsize=7)
|
||||
fig.colorbar(cax, ax=ax, fraction=0.046, pad=0.04, label="Présence (1 si minifig)")
|
||||
elif value > 1:
|
||||
ax.text(j, i, str(value), ha="center", va="center", color="#0d0d0d", fontsize=7)
|
||||
fig.colorbar(cax, ax=ax, fraction=0.046, pad=0.04, label="Nombre de minifigs")
|
||||
ensure_parent_dir(destination_path)
|
||||
fig.tight_layout()
|
||||
fig.savefig(destination_path, dpi=160)
|
||||
|
||||
Reference in New Issue
Block a user