Exploring Baseball with Python and d3.js

Jan 19, 2015 - 2 mins

Python

In the notebook I looked at pitch distributions at home plate, compared the pitches styles of Justin Verlander vs Yu Darvish and more. Notably I discovered the Eephus pitch!

One of the many interesting finds was that Verlander’s fastball gradually becomes faster over the course of the game.

Verlander Image

Matplotlib by itself can be a bit of a hassle to start out with. Luckily there’s a wonderful ggplot library for Python.

The entire notebook can be viewed here.

d3.js

I was curious about hit distributions over the field. Teams defense now regularly employ defensive shifts vs. certain hitters.

A shift is when the defense shifts more heavily to one side of the field.

A defensive shift

Now, clearly this leaves huge defensive gap in a section of the field, right field in the case of the image above. However if you have prior knowledge that a hitter’s hits heavily favour one side the tradeoff can be well worth it.

I had not used d3.js prior to this, so I figured why not?

I made an interactive visualization tool over a very generic baseball field that let’s you query via pitchers and hitters.

David Ortiz is known favour right field.

Ortiz hits

As we can see most hits are towards center and right field! You might be worried about the center but even in a shift center field is quite well covered.

You can play around with the project here.