feat: normalize plot to angle

This commit is contained in:
raiot 2024-11-08 14:26:27 +08:00
parent 0f4e10c6aa
commit 48d4337ed0
1 changed files with 7 additions and 3 deletions

View File

@ -15,6 +15,10 @@ def plot_servo_data(csv_file):
print(f"Error reading CSV file: {e}")
sys.exit(1)
# Preprocess data: subtract 500 and multiply by 0.5
for servo in ['Servo 1', 'Servo 2', 'Servo 3']:
df[servo] = (df[servo] - 500) * 0.25
# Set plot style
sns.set_style("whitegrid")
plt.figure(figsize=(12, 6))
@ -25,9 +29,9 @@ def plot_servo_data(csv_file):
sns.lineplot(data=df, x='Step', y='Servo 3', label='Servo 3')
# Set title and labels
plt.title('Servo Angles vs Time')
plt.title('Servo Angles vs Time (Normalized)')
plt.xlabel('Time (seconds)')
plt.ylabel('Angle')
plt.ylabel('Angle (degrees)')
# Add legend
plt.legend(title='Servo ID')
@ -36,7 +40,7 @@ def plot_servo_data(csv_file):
plt.tight_layout()
# Generate output filename based on input
output_file = csv_file.rsplit('.', 1)[0] + '_plot.png'
output_file = csv_file.rsplit('.', 1)[0] + '_normalized_plot.png'
# Save plot
plt.savefig(output_file, dpi=300, bbox_inches='tight')