File size: 1,642 Bytes
c75151e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from __future__ import annotations
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go


def movement_scatter_xy(
    df: pd.DataFrame, color="pitch_type", facet_by_handedness=False
):
    dfp = df.copy()
    if facet_by_handedness:
        fig = px.scatter(
            dfp,
            x="hb_as_in",
            y="ivb_in",
            color=color,
            facet_col="p_throws",
            hover_data=[
                "player_name",
                "pitch_type",
                "p_throws",
                "velo",
                "whiff_rate",
                "gb_rate",
                "csw",
            ],
        )
    else:
        fig = px.scatter(
            dfp,
            x="hb_as_in",
            y="ivb_in",
            color=color,
            hover_data=[
                "player_name",
                "pitch_type",
                "p_throws",
                "velo",
                "whiff_rate",
                "gb_rate",
                "csw",
            ],
        )
    fig.update_layout(
        xaxis_title="Horizontal: Arm-Side (+)  |  Glove-Side (−)",
        yaxis_title="Vertical: Ride (+)  |  Drop (−)",
        legend_title_text=color,
    )
    fig.add_hline(y=0, line_dash="dot")
    fig.add_vline(x=0, line_dash="dot")
    return fig


def radar_quality(row: pd.Series):
    cats = ["csw", "whiff_rate", "gb_rate", "zone_pct"]
    vals = [row[c] for c in cats]
    fig = go.Figure(data=go.Scatterpolar(r=vals, theta=cats, fill="toself"))
    fig.update_layout(
        polar=dict(radialaxis=dict(visible=True, range=[0, 1])), showlegend=False
    )
    return fig