SportsDataTutorials

15 tutorials

Baseball

MLB Statcast is the richest free data in sports. Pull it with pybaseball and build leaderboards, heatmaps and more.

Start with the pybaseball first-pull tutorial to get real Statcast data flowing, then the Pythagorean expected-standings tutorial to learn the win-expectation toolkit. From there the exit-velocity leaderboard, pitch-location heatmap and spray-chart builds are independent — pick whichever output you want to own first. Nine of the fifteen run start to finish on the bundled 2023 standings file, so an outage cannot stop them; the six Statcast builds need a live pybaseball pull and each says so on its own page.

Level:

Pull Your First MLB Data with pybaseball

Install pybaseball, turn on caching, and pull a week of real Statcast data — ending with an exit-velocity histogram that proves the data is really there.

BaseballBeginner~8 min

Your first real Statcast pull, cached, with an exit-velocity histogram.

Stacked Bar Charts: Win-Loss Composition

Stack wins and losses into one bar per team to show composition — and learn when stacking clarifies a comparison and when it just muddies the picture.

BaseballBeginner~5 min

Wins and losses stacked into a single bar per team to show composition.

fill_between: Shade Above and Below a Baseline

fill_between() paints the area between two lines; its where= mask colors above- and below-average regions differently, with interpolate=True closing the wedge.

BaseballBeginner~5 min

A run-differential line shaded green above the league average and red below it.

Make a Pitch-Location Heatmap in Python

Use a single pitcher's Statcast data to build a 2-D location heatmap, draw the strike zone from the catcher's view, and read what the hot spots tell you.

BaseballIntermediate~8 min

A pitch-location heatmap for one pitcher with the strike zone drawn on top.

Build a Hitter's Spray Chart

Turn Statcast hit coordinates into a spray chart on a field you draw yourself, colored by outcome, to see whether a hitter pulls or uses the whole field.

BaseballIntermediate~9 min

A hitter's batted balls plotted on a baseball field, by outcome.