from __future__ import annotations import pandas as pd import plotly.express as px import plotly.graph_objects as go def create_pitch_movement_chart(df: pd.DataFrame) -> go.Figure: if df.empty or "pfx_x" not in df.columns or "pfx_z" not in df.columns: return go.Figure() color_col = "pitch_type" if "pitch_type" in df.columns else None fig = px.scatter( df, x="pfx_x", y="pfx_z", color=color_col, title="Pitch Movement", labels={"pfx_x": "Horizontal Break", "pfx_z": "Vertical Break"}, opacity=0.75, ) fig.update_layout(template="plotly_dark") return fig