File size: 647 Bytes
72bdf20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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