Plotting log files - Blueye SDK

Skip to content

# Plotting

This example shows how one can pull a log file from the drone and use pandas and matplotlib to plot it.

We'll start by downloading a log file from the drone

    from blueye.sdk import Drone

    myDrone = Drone()

    myDrone.logs[0].download(output_name="log0.csv")

We can now read the csv-file into a pandas object for easy manipulation

    import pandas

    divelog = pandas.read_csv("log0.csv")

and then we'll convert the unix timestamp in `rt_clock` into a more readable format:

    divelog["rt_clock"] = pandas.to_datetime(divelog["rt_clock"], unit="s")

Next we will plot depth vs time with matplotlib:

    import matplotlib.pyplot as plt

    # Instantiate our figure and axes to plot on
    figure, axes = plt.subplots()

    x = divelog["rt_clock"]
    y = divelog["depth"] / 1000  # Dividing by 1000 to get depth in meters

    # Plot the depth values against time
    axes.plot(x, y, label="depth")

    # Set title, labels, and legend
    plt.title("Depth chart")
    plt.xlabel("Time")
    plt.ylabel("Depth [m]")
    plt.legend()

    # Save the figure
    figure.savefig("depth_plot.svg")

This should yield us a plot that looks something like this:

See the matplotlib documentation for more ways to plot your data.