Skip to content

Instantly share code, notes, and snippets.

@juhasch
Created October 30, 2025 08:51
Show Gist options
  • Select an option

  • Save juhasch/5a6ea309b7a8308898749974845c6874 to your computer and use it in GitHub Desktop.

Select an option

Save juhasch/5a6ea309b7a8308898749974845c6874 to your computer and use it in GitHub Desktop.
Create plot from log output
"""
Create matplotlib plots from logfiles created by the example scripts of https://github.com/juhasch/go2_webrtc_connect
e.g. looking like
🤖 State #51: Mode=0, Progress=0, Gait=0, Height=0.315m, Roll=0.029, Pitch=-0.033, Yaw=-0.013
🤖 State #52: Mode=0, Progress=0, Gait=0, Height=0.321m, Roll=0.035, Pitch=-0.073, Yaw=-0.017
🤖 State #53: Mode=0, Progress=0, Gait=0, Height=0.329m, Roll=0.044, Pitch=-0.145, Yaw=-0.025
"""
import re
import argparse
import matplotlib.pyplot as plt
def parse_logfile(filename):
"""
Liest die Logdatei und extrahiert State, Height, Roll, Pitch, Yaw.
"""
pattern = re.compile(
r"State #(?P<state>\d+):.*?Height=(?P<height>[-\d.]+)m,"
r" Roll=(?P<roll>[-\d.]+), Pitch=(?P<pitch>[-\d.]+), Yaw=(?P<yaw>[-\d.]+)"
)
states, heights, rolls, pitches, yaws = [], [], [], [], []
with open(filename, "r") as f:
for line in f:
match = pattern.search(line)
if match:
states.append(int(match.group("state")))
heights.append(float(match.group("height")))
rolls.append(float(match.group("roll")))
pitches.append(float(match.group("pitch")))
yaws.append(float(match.group("yaw")))
return states, heights, rolls, pitches, yaws
def plot_states(states, heights, rolls, pitches, yaws):
"""
Zeichnet Height, Roll, Pitch und Yaw gegen den State-Index.
"""
plt.figure(figsize=(12, 6))
plt.plot(states, heights, marker='o', label="Height (m)")
plt.plot(states, rolls, marker='s', label="Roll (rad)")
plt.plot(states, pitches, marker='^', label="Pitch (rad)")
plt.plot(states, yaws, marker='x', label="Yaw (rad)")
plt.xlabel("State #")
plt.ylabel("Values")
plt.title("Height, Roll, Pitch, and Yaw across States")
plt.legend()
plt.grid(True)
plt.show()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Parse log file and plot Height, Roll, Pitch, and Yaw data")
parser.add_argument("--log_file", "-f", default="log.txt",
help="Path to the log file to parse (default: log.txt)")
args = parser.parse_args()
log_file = args.log_file
states, heights, rolls, pitches, yaws = parse_logfile(log_file)
plot_states(states, heights, rolls, pitches, yaws)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment