Update functions/PitchPlotFunctions.py
Browse files
functions/PitchPlotFunctions.py
CHANGED
|
@@ -14,7 +14,6 @@ import matplotlib.patches as mpatches
|
|
| 14 |
import matplotlib.lines as mlines
|
| 15 |
from matplotlib.figure import Figure
|
| 16 |
import api_scraper
|
| 17 |
-
import matplotlib
|
| 18 |
|
| 19 |
# Initialize the scraper
|
| 20 |
scraper = api_scraper.MLB_Scrape()
|
|
@@ -371,39 +370,12 @@ class PitchPlotFunctions:
|
|
| 371 |
ax.invert_xaxis()
|
| 372 |
ax.text(24.5, -24.5, s='← Arm Side', fontstyle='italic', ha='left', va='bottom', bbox=dict(facecolor='white', edgecolor='black'), fontsize=13, zorder=3)
|
| 373 |
ax.text(-24.5, -24.5, s='Glove Side →', fontstyle='italic', ha='right', va='bottom', bbox=dict(facecolor='white', edgecolor='black'), fontsize=13, zorder=3)
|
| 374 |
-
# # After setting limits
|
| 375 |
-
# ax.set_xlim((-25, 25))
|
| 376 |
-
# ax.set_ylim((-25, 25))
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
# Set aspect ratio and apply clipping
|
| 380 |
-
ax.set_aspect('equal', adjustable='box')
|
| 381 |
-
|
| 382 |
-
ax.set_position([0.15, 0.15, 0.7, 0.7])
|
| 383 |
-
|
| 384 |
-
# Get the bbox from the axis data area
|
| 385 |
-
bbox = ax.get_window_extent().transformed(ax.figure.dpi_scale_trans.inverted())
|
| 386 |
-
|
| 387 |
-
# Set clip box for the main plot area
|
| 388 |
-
ax.set_clip_box(bbox)
|
| 389 |
-
ax.set_clip_on(True)
|
| 390 |
-
|
| 391 |
|
| 392 |
-
#
|
| 393 |
-
|
| 394 |
-
if not isinstance(child, matplotlib.text.Text): # Don't clip text
|
| 395 |
-
child.set_clip_box(bbox)
|
| 396 |
-
child.set_clip_on(True)
|
| 397 |
-
|
| 398 |
-
# Format tick labels
|
| 399 |
ax.xaxis.set_major_formatter(FuncFormatter(lambda x, _: int(x)))
|
| 400 |
ax.yaxis.set_major_formatter(FuncFormatter(lambda x, _: int(x)))
|
| 401 |
-
|
| 402 |
-
# Make sure the spines are included in the clip box
|
| 403 |
-
for spine in ax.spines.values():
|
| 404 |
-
spine.set_clip_box(bbox)
|
| 405 |
-
spine.set_clip_on(True)
|
| 406 |
-
|
| 407 |
### BREAK PLOT ###
|
| 408 |
def break_plot_big_long(self, df: pl.DataFrame, ax: plt.Axes, sport_id: int):
|
| 409 |
"""
|
|
@@ -572,7 +544,7 @@ class PitchPlotFunctions:
|
|
| 572 |
|
| 573 |
# Create a figure and a gridspec with 6 rows and 5 columns
|
| 574 |
fig = plt.figure(figsize=(9, 9))
|
| 575 |
-
gs = gridspec.GridSpec(6, 5, figure=fig, height_ratios=[0.
|
| 576 |
gs.update(hspace=0.1, wspace=0.1)
|
| 577 |
# Create subplots for player headshot, bio, and logo
|
| 578 |
ax_headshot = fig.add_subplot(gs[1, 1])
|
|
@@ -643,13 +615,6 @@ class PitchPlotFunctions:
|
|
| 643 |
ax_bottom_border.axis('off')
|
| 644 |
ax_footer.axis('off')
|
| 645 |
ax_legend.axis('off')
|
| 646 |
-
# Add clip path to constrain brush
|
| 647 |
-
# ax_main_plot.set_xlim(-25,25)
|
| 648 |
-
# ax_main_plot.set_ylim(-25,25)
|
| 649 |
-
ax_main_plot.set_clip_on(True)
|
| 650 |
-
ax_main_plot.patch.set_clip_on(True)
|
| 651 |
-
for artist in ax_main_plot.get_children():
|
| 652 |
-
artist.set_clip_on(True)
|
| 653 |
|
| 654 |
# Adjust layout and show the figure
|
| 655 |
# fig.tight_layout()
|
|
|
|
| 14 |
import matplotlib.lines as mlines
|
| 15 |
from matplotlib.figure import Figure
|
| 16 |
import api_scraper
|
|
|
|
| 17 |
|
| 18 |
# Initialize the scraper
|
| 19 |
scraper = api_scraper.MLB_Scrape()
|
|
|
|
| 370 |
ax.invert_xaxis()
|
| 371 |
ax.text(24.5, -24.5, s='← Arm Side', fontstyle='italic', ha='left', va='bottom', bbox=dict(facecolor='white', edgecolor='black'), fontsize=13, zorder=3)
|
| 372 |
ax.text(-24.5, -24.5, s='Glove Side →', fontstyle='italic', ha='right', va='bottom', bbox=dict(facecolor='white', edgecolor='black'), fontsize=13, zorder=3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
|
| 374 |
+
# Set aspect ratio and format tick labels
|
| 375 |
+
ax.set_aspect('equal', adjustable='box')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
ax.xaxis.set_major_formatter(FuncFormatter(lambda x, _: int(x)))
|
| 377 |
ax.yaxis.set_major_formatter(FuncFormatter(lambda x, _: int(x)))
|
| 378 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
### BREAK PLOT ###
|
| 380 |
def break_plot_big_long(self, df: pl.DataFrame, ax: plt.Axes, sport_id: int):
|
| 381 |
"""
|
|
|
|
| 544 |
|
| 545 |
# Create a figure and a gridspec with 6 rows and 5 columns
|
| 546 |
fig = plt.figure(figsize=(9, 9))
|
| 547 |
+
gs = gridspec.GridSpec(6, 5, figure=fig, height_ratios=[0.00000000005, 5, 30, 7, 2, 0.00000000005], width_ratios=[1, 10, 10, 10, 1])
|
| 548 |
gs.update(hspace=0.1, wspace=0.1)
|
| 549 |
# Create subplots for player headshot, bio, and logo
|
| 550 |
ax_headshot = fig.add_subplot(gs[1, 1])
|
|
|
|
| 615 |
ax_bottom_border.axis('off')
|
| 616 |
ax_footer.axis('off')
|
| 617 |
ax_legend.axis('off')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 618 |
|
| 619 |
# Adjust layout and show the figure
|
| 620 |
# fig.tight_layout()
|