Skip to content

Instantly share code, notes, and snippets.

@Shinichi-Nakagawa
Created March 21, 2016 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shinichi-Nakagawa/a7cb78c3cee8b713eb2a to your computer and use it in GitHub Desktop.
Save Shinichi-Nakagawa/a7cb78c3cee8b713eb2a to your computer and use it in GitHub Desktop.
岩隈久志(SEA)のナイスピッチングをPythonで可視化(Jupyter,seaborn,pitchpx) ref: http://qiita.com/shinyorke/items/2c2e2c3976fc2d1ed051
# -*- coding: utf-8 -*-
class PitchPxConst(object):
# 球種はこのリンクを参照 http://pitchfx.texasleaguers.com/
PITCH_TYPES = {
'FA': 'Fastball',
'FF': 'four-seam Fastball',
'FT': 'two-seam Fastball',
'FC': 'Cut Fastball',
'FS': 'Split-finger Fastball',
'FO': 'Forkball',
'SI': 'Sinker',
'SL': 'Slider',
'CU': 'Curveball',
'KC': 'Knuckle Curve',
'EP': 'Ephuus',
'CH': 'Change-up',
'SC': 'Screwball',
'KN': 'Knuckleball',
'UN': 'Unknown',
}
# markers(matplotlib)
PITCH_TYPES_MARKERS = {
'FA': '.',
'FF': 'o',
'FT': ',',
'FC': 'p',
'FS': 'v',
'FO': 'v',
'SI': '>',
'SL': '<',
'CU': '+',
'KC': ',',
'EP': 'D',
'CH': 'o',
'SC': 'H',
'KN': '*',
'UN': 'x',
}
# colors(matplotlib)
PITCH_TYPES_COLORS = {
'FA': 'red',
'FF': 'red',
'FT': 'red',
'FC': 'red',
'FS': 'red',
'FO': 'blue',
'SI': 'red',
'SL': 'blue',
'CU': 'green',
'KC': 'yellow',
'EP': 'green',
'CH': 'green',
'SC': 'yellow',
'KN': 'white',
'UN': 'black',
}
$ pip install jupyter matplotlib pandas seaborn pitchpx
$ pitchpx --help
Options:
-s, --start TEXT Start Day(YYYYMMDD) [required]
-e, --end TEXT End Day(YYYYMMDD) [required]
-o, --out TEXT Output directory(default:".") [required]
--help Show this message and exit.
$ pitchpx -s 20150807 -e 20150807 -o ./data
$ pitchpx -s 20150812 -e 20150812 -o ./data
$ pitchpx -s 20150818 -e 20150818 -o ./data
$ pitchpx -s 20150807 -e 20150818 -o ./data
$ Jupyter notebook
from pitchpx.const import PitchPxConst
# 一試合の投球を可視化(pz:高さ, px:幅)
axarray = {day: None for day in iwakuma_pitch_data.keys()}
f, (axarray) = plt.subplots(1, len(iwakuma_pitch_data.keys()), sharey=True, figsize=(24,6))
# TODO ストライクゾーンを描きたかったが断念(誰かおしえて)
for i, day in enumerate(iwakuma_pitch_data.keys()):
axarray[i].set_title('Hisashi Iwakuma({day})'.format(day=day))
datasets = iwakuma_pitch_data[day]
for k, v in PitchPxConst.PITCH_TYPES.items():
ds = datasets.query('pitch_type=="{type}"'.format(type=k))
if ds.empty:
continue
ds.plot(
kind='scatter',
x='px',
y='pz',
label=PitchPxConst.PITCH_TYPES[k],
color=PitchPxConst.PITCH_TYPES_COLORS[k],
marker=PitchPxConst.PITCH_TYPES_MARKERS[k],
xlim=(-3.0, 3.0),
ylim=(-1.0, 6.0),
ax=axarray[i]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment