Visualization

There are three main functions in Cropbox used for visualization. For information regarding syntax, please check the reference.

plot()

The plot() function is used to plot two-dimensional graphs.

Two Vectors

Let's start by making a simple plot by using two vectors of discrete values.

x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

plot(x, y)
Example block output


Multiple Vectors

You can also plot multiple series, by using a vector of vectors.

plot(x, [x, y])
Example block output


DataFrame

We can also make a plot using a DataFrame and its columns. Recall that the simulate() function provides a DataFrame.

@system S(Controller) begin
    x ~ advance
    y1(x) => 2x ~ track
    y2(x) => x^2 ~ track
end

df = simulate(S; stop=10)

p = plot(df, :x, [:y1, :y2])
Example block output

plot!()

plot!() is an extension of the plot() function used to update an existing Plot object p by appending a new graph made with plot()

Example

@system S(Controller) begin
    x ~ advance
    y3(x) => 3x ~ track
end

df = simulate(S; stop=10)

plot!(p, df, :x, :y3)
Example block output

visualize()

The visualize() function is used to make a plot from an output collected by running simulations. It is essentially identical to running the plot() function with a DataFrame from the simulate() function, and can be seen as a convenient function to run both plot() and simulate() together.

Example

@system S(Controller) begin
    x ~ advance
    y1(x) => 2x ~ track
    y2(x) => x^2 ~ track
end

v = visualize(S, :x, [:y1, :y2]; stop=10, kind=:line)
x 0 5 10 y1 y2 0 50 100

visualize!()

visualize!() updates an existing Plot object p by appending a new graph generated with visualize().

Example

@system S(Controller) begin
    x ~ advance
    y3(x) => 3x ~ track
end

visualize!(v, S, :x, :y3; stop=10, kind=:line)
x 0 5 10 y1 y2 0 50 100

manipulate()

The manipulate function has two different methods for creating an interactive plot.

manipulate(f::Function; parameters, config=())

Create an interactive plot updated by callback f. Only works in Jupyter Notebook.

manipulate(args...; parameters, kwargs...)

Create an interactive plot by calling manipulate with visualize as a callback.