
Draw Baseball Fields and Spray Charts in matplotlib: baseball-field-viz
Background pybaseball's built-in spraychart() is convenient, but it doesn't support overlaying heatmaps — making it hard to visualize batted ball density by zone. To use seaborn's kdeplot or histplot on top of a baseball field, you need to draw the field manually in matplotlib. Writing the coordinate transform and field drawing code every time is tedious, so I packaged it. pip install baseball-field-viz PyPI : https://pypi.org/project/baseball-field-viz/ GitHub : https://github.com/yasumorishima/baseball-field-viz What baseball-field-viz provides Three functions for Statcast visualization: from baseball_field_viz import transform_coords , draw_field , spraychart Function Description transform_coords(df) Convert Statcast hc_x / hc_y to feet (home plate at origin) draw_field(ax) Draw a baseball field on a matplotlib Axes spraychart(ax, df, color_by='events') One-liner combining the two above Usage Quickstart import matplotlib.pyplot as plt from baseball_field_viz import spraychart fig ,
Continue reading on Dev.to Python
Opens in a new tab

