File size: 838 Bytes
ee18e64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

import pandas as pd
import plotly.express as px
import plotly.graph_objects as go


def create_matchup_score_chart(df: pd.DataFrame) -> go.Figure:
    if df.empty:
        return go.Figure()

    fig = px.bar(
        df,
        x="player_name",
        y="matchup_score",
        title="Best Batter vs Pitcher Matchups",
    )
    fig.update_layout(template="plotly_dark", xaxis_title="", yaxis_title="Matchup Score")
    return fig


def create_hit_hr_chart(df: pd.DataFrame) -> go.Figure:
    if df.empty:
        return go.Figure()

    fig = px.scatter(
        df,
        x="hit_prob",
        y="hr_prob",
        hover_name="player_name",
        size="matchup_score",
        title="Hit Probability vs Home Run Probability",
    )
    fig.update_layout(template="plotly_dark")
    return fig