1

Compare la répartition des genres minifigs vs personnages

This commit is contained in:
2025-12-03 22:55:05 +01:00
parent cc613a88af
commit a976b57afe
6 changed files with 142 additions and 7 deletions

View File

@@ -25,12 +25,7 @@ def plot_minifig_gender_share(counts_path: Path, destination_path: Path) -> None
genders = [row["gender"] for row in rows]
counts = [int(row["minifig_count"]) for row in rows]
colors = [GENDER_COLORS.get(gender.strip().lower(), GENDER_COLORS["unknown"]) for gender in genders]
total = sum(counts)
labels = []
for gender, count in zip(genders, counts):
percent = (count / total) * 100 if total else 0
label = f"{GENDER_LABELS.get(gender.strip().lower(), 'Inconnu')} ({percent:.1f} %)"
labels.append(label)
labels = [f"{GENDER_LABELS.get(g.strip().lower(), 'Inconnu')} ({count})" for g, count in zip(genders, counts)]
fig, ax = plt.subplots(figsize=(6, 6))
ax.pie(
@@ -48,3 +43,31 @@ def plot_minifig_gender_share(counts_path: Path, destination_path: Path) -> None
fig.tight_layout()
fig.savefig(destination_path, dpi=160)
plt.close(fig)
def plot_character_gender_share(counts_path: Path, destination_path: Path) -> None:
"""Trace un diagramme circulaire de la répartition des personnages par genre."""
rows = [row for row in load_gender_counts(counts_path) if row["gender"].strip().lower() in ("male", "female")]
if not rows:
return
genders = [row["gender"] for row in rows]
counts = [int(row["character_count"]) for row in rows]
colors = [GENDER_COLORS.get(gender.strip().lower(), GENDER_COLORS["unknown"]) for gender in genders]
labels = [f"{GENDER_LABELS.get(g.strip().lower(), 'Inconnu')} ({count})" for g, count in zip(genders, counts)]
fig, ax = plt.subplots(figsize=(6, 6))
ax.pie(
counts,
labels=labels,
colors=colors,
startangle=90,
wedgeprops={"linewidth": 0.6, "edgecolor": "#0d0d0d"},
)
centre_circle = plt.Circle((0, 0), 0.5, fc="white")
ax.add_artist(centre_circle)
ax.set_title("Répartition des personnages par genre (hors inconnus)")
ensure_parent_dir(destination_path)
fig.tight_layout()
fig.savefig(destination_path, dpi=160)
plt.close(fig)