zyedidia / AnimatedPlots.jl

Fast animated (and static) plots for Julia
Other
17 stars 2 forks source link

Draw line plot #1

Open bdeonovic opened 9 years ago

bdeonovic commented 9 years ago

This package looks great! I didn't dig too deep yet, but I was wondering if it was possible to draw the evolution of a line plot over time (I have the x and y coordinates and would like to see them plotted out to see how the line traverses the x-y plane).

zyedidia commented 9 years ago

Sure! Keep in mind, this package is fairly limited, but it's possible to do what you want. Are you looking to make an animated plot or a static plot? If you want an animated graph, then the x axis will be time.

You'll want to make a function which returns the y coordinates and then you can plot it over time:

using AnimatedPlots

function fun(x)
    return y
end

animated_fun = AnimatedGraph(fun)

plot(animated_fun)

# If you want the camera to follow the plot (it will only follow in the x direction)
# follow(animated_fun)

waitfor(current_window())
bdeonovic commented 9 years ago

Would it be possible to have static x,y coordinates (the x-y plane) and then as time goes on have the x,y coords be plotted on the plane (connected by lines, as if someone was drawing my points).

zyedidia commented 9 years ago

Oh, I see what you mean. Yes you can do that. Make sure that you re-clone the package as I got rid of some warnings. Here's an example for you:

using AnimatedPlots

x_coords = [0, 3, 4, 6, 8]
y_coords = [4, 7, 2, 9, 6]

function fun(x)
    if x in x_coords
        y_coords[findfirst(x_coords, x)] 
    else
        nothing
    end
end

plot(AnimatedGraph(fun))

waitfor(current_window())