In [1]:
import pandas as pd
import pybaseball as pb
import as px
In [2]:
def create_chart(last_name, first_name, chart_type):
    start_date = "2019-01-01" 
    end_date = "2019-12-31"
    key = pb.playerid_lookup(last_name, first_name)["key_mlbam"].values[0] # get unique pitcher identifier   
    data = pb.statcast_pitcher(start_date, end_date, key) # get dataset of pitches thrown by pitcher
    data = data.sort_values(["pitch_number"]) # sort pitches by order thrown, earliest first
    data = data.dropna(subset=['pitch_type']) # make sure dataset does not contain nulls

    data["seq"] = data.reset_index().index # create new column with pitch order
    if chart_type == "scatter":
        fig = px.scatter(data, x="seq", y="release_speed", color="pitch_type", 
                         title=f'{first_name} {last_name} 2019 Pitches Release Speed') # create chart
    elif chart_type =="box":
        fig =, x="pitch_type", y="release_speed")
    return fig
In [3]:
create_chart("Cole", "Gerrit", "scatter")
Gathering player lookup table. This may take a moment.
Gathering Player Data