"""Genera el lollipop de PERFIL DEFENSIVO de San Lorenzo (idéntico al de la sección 'Equipos y variables' del Space) y lo guarda como PNG para la presentación. Verde = z del equipo; diamante amarillo = mejor de la liga; columnas z y ranking.""" import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt from matplotlib.lines import Line2D from matplotlib.markers import MarkerStyle from racing_reports import team_vars as tv LEAGUE, SEASON, TEAM = "Liga Profesional Argentina", "26", "San Lorenzo" VARS = [ "goles_transicion_rival", "situacion_fast_break_rival", "acciones_defensivas_en_ofensiva", "agresividad_offside", "altura_media_recuperacion", "avg_altura_offside", "ballrecovery", "big_chances_generadas_rival", "clearance_totales", "duelos_aereos_ganados", "goles_regular_play_rival", "goles_tempranos_rival", "goles_totales_rival", "intercepciones", "pases_peligrosos_exitosos_con_centros_rival", "pases_progresivos_exitosos_rival", "pct_centros_pases_totales_ultimo_tercio_rival", "pct_duelos_aereos_ganados", "pct_pases_exitosos_t3_rival", "velocidad_progresion_m_por_s_rival", "xg_suma_tiros_rival", ] BG = "#1b3a32"; GREEN = "#3ddc84"; RED = "#e8584e"; YEL = "#f2c14e"; TXT = "#e8eeea"; MUT = "#9fb4ab" prof = tv.team_profile(LEAGUE, SEASON, TEAM, VARS, scope="liga") items = prof["items"] n = prof["pool_size"] items = items[::-1] # primera variable arriba fig, ax = plt.subplots(figsize=(13, 9), facecolor=BG) ax.set_facecolor(BG) y = range(len(items)) for i, it in enumerate(items): z = it["z"] or 0.0 c = GREEN if z >= 0 else RED ax.plot([0, z], [i, i], color=c, lw=2.5, zorder=2, solid_capstyle="round") ax.scatter([z], [i], s=130, color=c, zorder=3, edgecolors=BG, linewidths=1.5) mz = it.get("mejor_liga_z") if mz is not None: ax.scatter([mz], [i], marker=MarkerStyle("D"), s=95, color=YEL, zorder=4, edgecolors=BG, linewidths=1.2) # etiqueta izquierda (con flecha ↓ si negativa) lab = ("↓" if it["negativa"] else "") + it["label"] if len(lab) > 32: lab = lab[:31] + "…" ax.text(-3.25, i, lab, ha="right", va="center", color=(YEL if it["negativa"] else TXT), fontsize=11) # z y ranking a la derecha ax.text(3.55, i, f"{z:+.2f}", ha="right", va="center", color=c, fontsize=11, fontweight="bold") ax.text(4.35, i, f"{it['rank']}/{n}", ha="right", va="center", color=MUT, fontsize=10) ax.axvline(0, color=MUT, lw=1, ls=(0, (4, 3)), alpha=0.6, zorder=1) for xg in (-3, 3): ax.axvline(xg, color="#33514a", lw=0.8, alpha=0.5, zorder=0) ax.set_xlim(-3.2, 3.2); ax.set_ylim(-0.7, len(items) - 0.3) ax.set_yticks([]); ax.set_xticks([-3, 0, 3]); ax.set_xticklabels(["-3", "0", "+3"], color=MUT, fontsize=10) for s in ax.spines.values(): s.set_visible(False) ax.text(3.55, len(items) - 0.1, "z", ha="right", va="center", color=MUT, fontsize=10) ax.text(4.35, len(items) - 0.1, "ranking", ha="right", va="center", color=MUT, fontsize=10) ax.set_title(f"San Lorenzo (Liga Profesional Argentina · 26) · vs su liga-temporada · {n} equipos", color=TXT, fontsize=14, fontweight="bold", loc="left", pad=16) leg = [Line2D([0], [0], marker="o", color=BG, markerfacecolor=GREEN, markersize=11, label="Equipo"), Line2D([0], [0], marker="D", color=BG, markerfacecolor=YEL, markersize=10, label="Mejor de la liga")] ax.legend(handles=leg, loc="lower left", fontsize=10, facecolor="#16251e", edgecolor="#33514a", labelcolor=TXT, ncol=2, bbox_to_anchor=(0.0, -0.06)) out = Path(__file__).resolve().parents[1].parent / "Downloads" / "presentation-sanlorenzo" / "san_lorenzo" / "perfil_defensivo.png" out = Path("/Users/pagrois/Downloads/presentation-sanlorenzo/san_lorenzo/perfil_defensivo.png") fig.subplots_adjust(left=0.30, right=0.96, top=0.92, bottom=0.06) fig.savefig(out, dpi=130, facecolor=BG) print("guardado:", out, "| pool:", n, "| vars:", len(items))