kannst du folgenden Code bitte so ändern dass die Funktion "calculatesuccessratehexbin"…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
kannst du folgenden Code bitte so ändern dass die Funktion "calculate_success_rate_hexbin" auch genutzt wird um die Farbe der hexelemente und die Farbe des der Color bar richtig zu setzen? Die Größe der Hex elemente soll weiterhin wie in bisher die Anzahl an Würfe pro Hex-Zelle repräsentieren.
import matplotlib.pyplot as plt import numpy as np import pandas as pd from matplotlib.patches import PathPatch from matplotlib.path import Path from matplotlib.collections import PatchCollection
Wurf-Koordinaten extrahieren
x_coords = single_player_all_games_team['coordinate_x_raw'].values y_coords = single_player_all_games_team['coordinate_y_single_side_adj'].values scoring_play = single_player_all_games_team['scoring_play'].astype(int).values
Erfolgsquote berechnen
Gruppen der Koordinaten und Erfolgsquote berechnen
df = pd.DataFrame({ 'x': x_coords, 'y': y_coords, 'scoring_play': scoring_play })
Definiere eine Funktion zur Berechnung der Erfolgsquote
def calculate_success_rate(x, y): group = df[(np.abs(df['x'] - x) < gridsize) & (np.abs(df['y'] - y) < gridsize)] if len(group) > 0: return group['scoring_play'].mean() else: return 0
Funktion zum Berechnen der Erfolgsquote für jeden Hexagon
def calculate_success_rate_hexbin(x_coords, y_coords, scoring_play, gridsize): # Hexbin erstellen hexbin = plt.hexbin(x_coords, y_coords, gridsize=gridsize, mincnt=1, edgecolors='black', cmap='viridis', reduce_C_function=lambda c: calculate_success_rate(x, y)) return hexbin
Basketballfeld erstellen
fig, ax = plt.subplots(figsize=(12, 12))
rect = plt.Rectangle((0, 0), court_width, court_length, linewidth=1, edgecolor='black', facecolor='none') ax.add_patch(rect)
Funktion zur Zeichnung der Drei-Punkte-Linie
def draw_three_point_line(ax, center_x, center_y, radius, side): theta = np.linspace(2.42/20 * np.pi, (17.58/20) * np.pi, 500) x_arc = center_x + radius * np.cos(theta) y_arc = center_y + side * radius * np.sin(theta) ax.plot(x_arc, y_arc, color='black')
if 1: # Drei-Punkte-Linien zeichnen three_point_lines_circle_offset = 4 + 1.5 three_point_lines_circle_radius = 23.75 draw_three_point_line(ax, court_width / 2, three_point_lines_circle_offset, three_point_lines_circle_radius, 1) draw_three_point_line(ax, court_width / 2, court_length - three_point_lines_circle_offset, three_point_lines_circle_radius, -1)
code Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.