Syntrex's picture
Rename visualization/matchup.txt to visualization/matchup.py
ee18e64 verified
raw
history blame
838 Bytes
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