Cannot plot with Gadfly when running script with `julia -i`

212 Views Asked by At

When running julia REPL from the command line and copy-pasting my script, the Gadfly plot command works as expected.

But, when running julia -i scriptname.jl plot no longer works and prints:

julia> DataFrame(CSV.File("file.csv"))
julia> plot(massdf, x=:date, y=:mass, group=:day, color=:day, Geom.line)
Plot(...)

julia>

Is there a setting needed to make it work?

1

There are 1 best solutions below

1
EricLavault On

You need to explicitly display the output of plot() in your script (which is done implicitly in a Read-Eval-Print-Loop but not when the whole script is executed, even with -i).

Use display(p::Plot), or draw(backend::Compose.Backend, p::Plot) :

df = DataFrame(CSV.File("file.csv"))
p = plot(df, x=:date, y=:mass, group=:day, color=:day, Geom.line)
display(p)

See also Gadfly Backends.