schorrm / pybaseball

I'm maintaining the original repo now. please go to github.com/jldbc/pybaseball
MIT License
23 stars 8 forks source link

Add plotting functions #9

Closed andersonfrailey closed 4 years ago

andersonfrailey commented 4 years ago

I stumbled on the MLBAM stadium coordinates in this repo and wrote a couple functions for plotting. I used altair, but I'd be happy to switch to matplotlib or bokeh if that's preferable.

The first, plot_stadium, just returns a plot with the stadium outline. spraychart makes a spraychart using statcast data. Example: spraychart

schorrm commented 4 years ago

This is really nice! Is it possible to handle the aspect ratio here differently?

schorrm commented 4 years ago

Added include_package_data=True to setup.py, so it'll actually install the CSV file.

schorrm commented 4 years ago

I don't see any reason why not Altair, at least right now. Can we get that plot to be not squishy? And another maybe convenience mechanism -- can we make a simple flag to color by result?

andersonfrailey commented 4 years ago

Yeah I've been working on the aspect ratio. Just need to play with the width and height of the plot. Gonna push some changes up soon.

can we make a simple flag to color by result?

As in like single, double, out, etc., right? Yep, there is. I'll include that in the changes.

schorrm commented 4 years ago

Also -- not pinning this on you in any way, but more making a note to self -- since we have this (and statcast data) -- we should make a similar thing for pitch location charts

andersonfrailey commented 4 years ago

Here's the new look spraychart

we should make a similar thing for pitch location charts

Agreed here. A lot of great features we could add.

schorrm commented 4 years ago

I think I found an improvement for aspect ratio image

schorrm commented 4 years ago

I think it's better with this -- feel free to rollback the commit if you disagree

schorrm commented 4 years ago

@andersonfrailey ? What do you think?

andersonfrailey commented 4 years ago

Your change looks good to me! Any other feature/functionality you want me to add on?

schorrm commented 4 years ago

I think we're good in here -- I definitely want to use this as the basis for some more stuff that's related, like pitcher sprays, but that'll come separately I assume. Oh, and if you have a new name suggestion, it may be worthwhile if we want to put the fork up on the PyPI.

schorrm commented 4 years ago

Oh, actually maybe one thing -- can we parametrize what the color is? I think outcome is the correct one for the default, but if, say, I wanted to plot Altuve's vs someone else's (assuming I concatted the DFs with their IDs / names etc). Maybe have that line in there creating the label column unconditionally (cheap enough, no need to add an if check), but just have color_by='label', legend='Outcome' in the parameters?

schorrm commented 4 years ago

This is already loads of fun image

andersonfrailey commented 4 years ago

Latest batch of commits added the ability to color by player and I added a subtitle to say which ballpark you're plotting on. Here's the new looks multiplayer_spraychart spraychart

I need to make a couple of tweaks to the subtile on the generic field. Will push those shortly.

andersonfrailey commented 4 years ago

Fixes are up. generic

schorrm commented 4 years ago

I liked it better with CIN but sure. And if someone really needs a generic stadium, there's always Kauffman. Great job, Imma merge. And a side note: for now I'm leaving the CSV where it is. If we start having other data files come with this thing, we'll move them to a separate folder.