|
| 1 | +import pandas as pd |
| 2 | +import matplotlib.pyplot as plt |
| 3 | + |
| 4 | +def plot_data(gyro_csv, accel_csv, rgb_csv, depth_csv, sensor_type): |
| 5 | + # Load the CSV data into DataFrames |
| 6 | + gyro_data = pd.read_csv(gyro_csv) |
| 7 | + accel_data = pd.read_csv(accel_csv) |
| 8 | + rgb_data = pd.read_csv(rgb_csv) |
| 9 | + depth_data = pd.read_csv(depth_csv) |
| 10 | + |
| 11 | + # Set up the plot with six subplots: timestamps, timestamp differences, global timestamps for all sensors |
| 12 | + fig, ax = plt.subplots(5, 1, figsize=(12, 24), sharex=True) |
| 13 | + |
| 14 | + # Plot timestamps for gyro and accelerometer |
| 15 | + ax[0].plot(gyro_data['Index'], gyro_data['Timestamp'], label='Gyro Timestamp', color='blue') |
| 16 | + ax[0].plot(accel_data['Index'], accel_data['Timestamp'], label='Accelerometer Timestamp', color='orange') |
| 17 | + ax[0].set_title('IMU Timestamps') |
| 18 | + ax[0].set_ylabel('Timestamp (us)') |
| 19 | + ax[0].legend() |
| 20 | + |
| 21 | + # Plot timestamps for RGB and depth sensors |
| 22 | + ax[1].plot(rgb_data['Index'], rgb_data['Timestamp'], label='RGB Timestamp', color='red') |
| 23 | + ax[1].plot(depth_data['Index'], depth_data['Timestamp'], label='Depth Timestamp', color='green') |
| 24 | + ax[1].set_title('Camera Timestamps') |
| 25 | + ax[1].set_ylabel('Timestamp (us)') |
| 26 | + ax[1].legend() |
| 27 | + |
| 28 | + # Plot timestamp differences for all sensors if the column exists |
| 29 | + if 'Timestamp Difference' in gyro_data.columns: |
| 30 | + ax[2].plot(gyro_data['Index'], gyro_data['Timestamp Difference'], label='Gyro Timestamp Difference', color='purple') |
| 31 | + ax[2].plot(accel_data['Index'], accel_data['Timestamp Difference'], label='Accelerometer Timestamp Difference', color='magenta') |
| 32 | + ax[2].plot(rgb_data['Index'], rgb_data['Timestamp Difference'], label='RGB Timestamp Difference', color='black') |
| 33 | + ax[2].plot(depth_data['Index'], depth_data['Timestamp Difference'], label='Depth Timestamp Difference', color='grey') |
| 34 | + ax[2].set_title('Timestamp Differences') |
| 35 | + ax[2].set_ylabel('Timestamp Difference (us)') |
| 36 | + ax[2].legend() |
| 37 | + |
| 38 | + # Plot global timestamps for all sensors if the column exists |
| 39 | + if 'Global Timestamp' in gyro_data.columns: |
| 40 | + ax[3].plot(gyro_data['Index'], gyro_data['Global Timestamp'], label='Gyro Global Timestamp', color='cyan') |
| 41 | + ax[3].plot(accel_data['Index'], accel_data['Global Timestamp'], label='Accelerometer Global Timestamp', color='yellow') |
| 42 | + ax[3].plot(rgb_data['Index'], rgb_data['Global Timestamp'], label='RGB Global Timestamp', color='brown') |
| 43 | + ax[3].plot(depth_data['Index'], depth_data['Global Timestamp'], label='Depth Global Timestamp', color='orange') |
| 44 | + ax[3].set_title('Global Timestamps') |
| 45 | + ax[3].set_ylabel('Global Timestamp (us)') |
| 46 | + ax[3].legend() |
| 47 | + |
| 48 | + # Plot global timestamp differences for all sensors if the column exists |
| 49 | + if 'Global Timestamp Difference' in gyro_data.columns: |
| 50 | + ax[4].plot(gyro_data['Index'], gyro_data['Global Timestamp Difference'], label='Gyro Global Timestamp Difference', color='orange') |
| 51 | + ax[4].plot(accel_data['Index'], accel_data['Global Timestamp Difference'], label='Accelerometer Global Timestamp Difference', color='brown') |
| 52 | + ax[4].plot(rgb_data['Index'], rgb_data['Global Timestamp Difference'], label='RGB Global Timestamp Difference', color='purple') |
| 53 | + ax[4].plot(depth_data['Index'], depth_data['Global Timestamp Difference'], label='Depth Global Timestamp Difference', color='magenta') |
| 54 | + ax[4].set_title('Global Timestamp Differences') |
| 55 | + ax[4].set_ylabel('Global Timestamp Difference (us)') |
| 56 | + ax[4].legend() |
| 57 | + |
| 58 | + # Adjust layout and show plot |
| 59 | + plt.tight_layout() |
| 60 | + plt.show() |
| 61 | + |
| 62 | +def main(): |
| 63 | + # Path to the gyro, accel, RGB, and depth CSV files |
| 64 | + gyro_csv = 'gyro_data.csv' |
| 65 | + accel_csv = 'accel_data.csv' |
| 66 | + rgb_csv = 'color_data.csv' |
| 67 | + depth_csv = 'depth_data.csv' |
| 68 | + |
| 69 | + # Plot all sensor data |
| 70 | + plot_data(gyro_csv, accel_csv, rgb_csv, depth_csv, 'Sensor Data') |
| 71 | + |
| 72 | +if __name__ == "__main__": |
| 73 | + main() |
0 commit comments