def do_plots(filename):
    with open(filename) as handle:
        plot_settings = yaml.load(handle)
    name = plot_settings['name']
    plots = plot_settings['plots']
    # first pass: plot one image for each pitch type
    for plot in plots:
        plot = defaultdict(lambda:None, plot) #if it's not mentioned in the yaml file, forget it
        pitchset = pitches(name=name, pitch_type = plot['pitch_type'], stand=plot['stand'],
                           payoff=plot['payoff'], des=plot['des'], event=plot['event'])

        fig = plt.figure()
        ax = fig.add_subplot(111)

        for call in ('X', 'S', 'B'):
            subset = pitchset[pitchset['type'] == call]
            norm_pz = normalized_pitch_height(subset)
            plt.plot(subset['px'],
                     norm_pz, c=plot_settings['colors'][call], marker=plot_settings['marker'], linestyle='None')

        #draw strike zone
        codes = [Path.MOVETO] + [Path.LINETO]*3 + [Path.CLOSEPOLY]
        vertices = [(-1,1.6), (1,1.6), (1, 3.65), (-1, 3.65), (0,0)]
        vertices = numpy.array(vertices, float)
        path = Path(vertices, codes)
        pathpatch = PathPatch(path, facecolor='None', edgecolor='black')
        ax.add_patch(pathpatch)

        plt.xlim([-3,3])
        plt.ylim([0,6])
        plt.savefig(plot['filename'], format='png')
def do_plots(filename):
    with open(filename) as handle:
        plot_settings = yaml.load(handle)
    name = plot_settings['name']
    plots = plot_settings['plots']
    # first pass: plot one image for each pitch type
    for plot in plots:
        plot = defaultdict(
            lambda: None,
            plot)  #if it's not mentioned in the yaml file, forget it
        pitchset = pitches(name=name,
                           pitch_type=plot['pitch_type'],
                           stand=plot['stand'],
                           payoff=plot['payoff'],
                           des=plot['des'],
                           event=plot['event'])

        fig = plt.figure()
        ax = fig.add_subplot(111)

        for call in ('X', 'S', 'B'):
            subset = pitchset[pitchset['type'] == call]
            norm_pz = normalized_pitch_height(subset)
            plt.plot(subset['px'],
                     norm_pz,
                     c=plot_settings['colors'][call],
                     marker=plot_settings['marker'],
                     linestyle='None')

        #draw strike zone
        codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
        vertices = [(-1, 1.6), (1, 1.6), (1, 3.65), (-1, 3.65), (0, 0)]
        vertices = numpy.array(vertices, float)
        path = Path(vertices, codes)
        pathpatch = PathPatch(path, facecolor='None', edgecolor='black')
        ax.add_patch(pathpatch)

        plt.xlim([-3, 3])
        plt.ylim([0, 6])
        plt.savefig(plot['filename'], format='png')
Exemple #3
0
import pdb


if len(sys.argv) != 2:
   print "python plot_pitch_locations.py lester_break.yaml"
else:
   with open(sys.argv[1]) as handle:
      plot_settings = yaml.load(handle)

db_settings, session = baseball.init()

name = plot_settings['name']

results = {}
results['sw_strike'] = pitches(session, name=name, pitch_type = plot_settings['pitch_type'],
                    des="Swinging Strike")
results['foul'] = pitches(session, name=name, pitch_type = plot_settings['pitch_type'],
                    des="Foul")
results['groundout']= pitches(session, name=name, pitch_type = plot_settings['pitch_type'],
      event="Groundout", payoff=True)
results['flyout']= pitches(session, name=name, pitch_type = plot_settings['pitch_type'],
      event="Flyout", payoff=True)
results['lineout']= pitches(session, name=name, pitch_type = plot_settings['pitch_type'],
      event="Lineout", payoff=True)
results['single'] = pitches(session, name=name, pitch_type = plot_settings['pitch_type'],
      event="Single", payoff=True)
results['double'] = pitches(session, name=name, pitch_type = plot_settings['pitch_type'],
      event="Double", payoff=True)
#results['triple'] = pitches(session, name=name, pitch_type = plot_settings['pitch_type'],
#      event="Triple", payoff=True)
results['homerun'] = pitches(session, name=name, pitch_type = plot_settings['pitch_type'],
Exemple #4
0
import pdb

if len(sys.argv) != 2:
    print "python plot_pitch_locations.py lester_break.yaml"
else:
    with open(sys.argv[1]) as handle:
        plot_settings = yaml.load(handle)

db_settings, session = baseball.init()

name = plot_settings['name']

results = {}
results['sw_strike'] = pitches(session,
                               name=name,
                               pitch_type=plot_settings['pitch_type'],
                               des="Swinging Strike")
results['foul'] = pitches(session,
                          name=name,
                          pitch_type=plot_settings['pitch_type'],
                          des="Foul")
results['groundout'] = pitches(session,
                               name=name,
                               pitch_type=plot_settings['pitch_type'],
                               event="Groundout",
                               payoff=True)
results['flyout'] = pitches(session,
                            name=name,
                            pitch_type=plot_settings['pitch_type'],
                            event="Flyout",
                            payoff=True)
Exemple #5
0

if len(sys.argv) != 2:
   print "python plot_pitch_types.py wakefield.yaml"
else:
   with open(sys.argv[1]) as handle:
      plot_settings = yaml.load(handle)

db_settings, session = baseball.init()

name = plot_settings['name']
plots = plot_settings['plots']

# first pass: plot one image for each pitch type
for plot in plots:
   pitchset = pitches(session, name=name, pitch_type = plot['pitch_type'])

   fig = plt.figure()
   ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True)
   ax.plot(map(to_radian, pitchset['break_angle']),
             pitchset['break_length'], c=plot['color'], marker=plot['marker'], linestyle='None')
   ax.set_rmax(18)
   plt.savefig(plot['filename'], format='png')

# second pass: plot one image including all types, color-coded
fig = plt.figure()
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True)
liness= []
namess= []
for plot in plots:
   pitchset = pitches(session, name=name, pitch_type = plot['pitch_type'])