@Hanna the flag belongs over the diagram. But the arrows are right. Thanks.
I finished the solution and I wanted to post the code:
%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import interact, Output
from IPython.display import display
# Beispiel-Daten erstellen
data = {
'Club Path': [5.89, 5.2, 4.9, 5.7],
'Face Angle': [3.12, 2.8, 3.3, 2.7]
}
df = pd.DataFrame(data)
# Ausgabe-Widget für das Diagramm
output = Output()
# Interaktive Tabelle erstellen
def create_table():
table = pd.DataFrame(df)
display(table)
# Funktion zum Zeichnen des Diagramms
def plot_data(selected_row):
# Calculating the angle in radians
selected_data = df.iloc[selected_row]
club_path = np.radians(selected_data['Club Path']) # Club Path
face_angle = np.radians(selected_data['Face Angle']) # Face Angle
# Create a figure and an axis
fig, ax = plt.subplots()
# Axis limits
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
# Draw x- and y-axis
ax.axhline(0, color='black', linewidth=0.5, ls='--')
ax.axvline(0, color='black', linewidth=1.5, ls='--')
# Draw angles
club_vector = np.array([np.sin(club_path), np.cos(club_path)])
face_vector = np.array([np.sin(face_angle), np.cos(face_angle)])
ax.quiver(0, 0, club_vector[0], club_vector[1], angles='xy', scale_units='xy', scale=1, color='blue', label='Club Path (5.89°)')
ax.quiver(0, 0, face_vector[0], face_vector[1], angles='xy', scale_units='xy', scale=1, color='orange', label='Face Angle (3.12°)')
# draw lines
ax.plot([0, -club_vector[0]], [0, -club_vector[1]], color='blue', linewidth=3)
ax.plot([0, -face_vector[0]], [0, -face_vector[1]], color='orange', linewidth=3)
# Calculte angle between the to vectors
dot_product = np.dot(club_vector, face_vector)
norm_club = np.linalg.norm(club_vector)
norm_face = np.linalg.norm(face_vector)
# Calculating the angle in radians
angle_radians = np.arccos(dot_product / (norm_club * norm_face))
angle_degrees = np.degrees(angle_radians)
# Add angle in ledgend
ax.legend(title=f"Face to Path: {angle_degrees:.2f}°")
# Delete diagram frame
for spine in ax.spines.values():
spine.set_visible(False)
# Delete x- and y-axis
ax.set_xticks([])
ax.set_yticks([])
# Print diagram
plt.show()
# Interaktive Auswahl der Zeile
def on_row_click(selected_row):
plot_data(selected_row)
# Tabelle anzeigen
create_table()
# Interaktive Auswahl der Zeile
interact(on_row_click, selected_row=(0, len(df)-1))
# Ausgabe-Widget anzeigen
display(output)
This is the solution. The only downside you need to klick the selector instead of the table row you wanna show.