Alright, we’re getting somewhere! Let me explain what’s happening with a script. In Julia, the plotting happens because the plot()
command returns a plot object. However, there is a difference between running a command in a script, and running a command in the REPL. In the REPL:
a = 2
automatically returns, while
a = 2;
does not (like MATLAB). However, that would make you have to put ;
everywhere in a script, and so
a = 2
does now return a
in a script. However, this means that plot(...)
doesn’t actually return anything to show in a script.
So the next thing we should do is make sure it works for you inside of a script. Once again, I’ll use Plotly since it should always be working (if you have a working web browser). Now put
using Plots; plotly()
display(plot(rand(10,10)))
inside of a .jl
file. Inside of the REPL, do include("filename.jl")
(use pwd()
to make sure you’re in the right directory, and cd("...")
around if you need to). This should display the plot.
Now I am not sure about getting julia filename.jl
to work directly from the terminal since Julia will exit when finishing its commands. Maybe that’s why it wasn’t working before? I generally just use Julia interactively (and I suspect many others do too).