Created
June 24, 2024 03:49
-
-
Save arif-pandu/a86ceb66b09cb59d87d5248c9cb4e316 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import matplotlib.pyplot as plt | |
def plot_scaled_graph_with_values(frame_0, frame_7, data): | |
""" | |
Plots the graph with the given data, scaling the values at frame 0 and frame 7, | |
and prints the scaled values per frame. | |
Parameters: | |
- frame_0: tuple (x0, y0, z0) values at frame 0 | |
- frame_7: tuple (x7, y7, z7) values at frame 7 | |
- data: dictionary containing the data with keys "Frame", "X", "Y", and "Z" | |
""" | |
df = pd.DataFrame(data) | |
# Scaling factors | |
scale_x = (frame_7[0] - frame_0[0]) / (df[df['Frame'] == 7]['X'].values[0] - df[df['Frame'] == 0]['X'].values[0]) | |
scale_y = (frame_7[1] - frame_0[1]) / (df[df['Frame'] == 7]['Y'].values[0] - df[df['Frame'] == 0]['Y'].values[0]) | |
scale_z = (frame_7[2] - frame_0[2]) / (df[df['Frame'] == 7]['Z'].values[0] - df[df['Frame'] == 0]['Z'].values[0]) | |
# Scaling the data | |
df['X'] = frame_0[0] + scale_x * (df['X'] - df['X'][0]) | |
df['Y'] = frame_0[1] + scale_y * (df['Y'] - df['Y'][0]) | |
df['Z'] = frame_0[2] + scale_z * (df['Z'] - df['Z'][0]) | |
# Print scaled values per frame | |
print("Scaled Values per Frame:") | |
print(df) | |
# Plotting the data | |
fig, ax = plt.subplots(figsize=(10, 6)) | |
ax.plot(df['Frame'], df['X'], label='X', marker='o') | |
ax.plot(df['Frame'], df['Y'], label='Y', marker='o') | |
ax.plot(df['Frame'], df['Z'], label='Z', marker='o') | |
ax.set_title('Frame vs X, Y, Z (Scaled)') | |
ax.set_xlabel('Frame') | |
ax.set_ylabel('Values') | |
ax.legend() | |
plt.grid(True) | |
plt.show() | |
# Guide for creating function | |
data = { | |
"Frame": [0, 3, 4, 5, 7], | |
"X": [0, 50.6748, 34.79839, 50.6748, 45], | |
"Y": [0, 1, 1, 1, 1], | |
"Z": [0, 20.0071, 32.31347, 20.0071, 29] | |
} | |
# Input desired end scale by replacing the (13, 13, 13) | |
# (13, 13, 13) are X, Y, Z in order | |
plot_scaled_graph_with_values((0, 0, 0), (13, 13, 13), data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment