I followed the documentation:
https://docs.juliaplots.org/latest/output/
and tried to write show=true and
using Plots
arr = [1.2, 1.4, 1.5, 1.1]
x = [1, 2, 3, 4]
p = scatter(x, arr)
display(p)
But no new window with the plot appears
I followed the documentation:
https://docs.juliaplots.org/latest/output/
and tried to write show=true and
using Plots
arr = [1.2, 1.4, 1.5, 1.1]
x = [1, 2, 3, 4]
p = scatter(x, arr)
display(p)
But no new window with the plot appears
How are you executing this snippet?
julia name_program.jl
Put a sleep(60)
at the end of the script to allow the Julia REPL time to display the plot before exiting the script.
Or go full interactive, and instead of
julia name_program.jl
execute
julia
include("name_program.jl")
(then when satisfied quit by exit()
or Ctrl-D
)
Tomorrow I will have my computer under my hands and I will try
Or try
julia -i script.jl
julia
include(“name_program.jl”)
This works, but sometimes it’s buggy and it works just the first time I use it. I need to quit the julia enviroment to show it again
julia -i script.jl
This works just the first time, as when I quit, it enters julia enviroment and i need to quit it before running the command again
Update: I’m trying to add logarithmic scale on y axis for scatter plot, but the overall experience is too buggy. Now even the label and ticks are gone away. I need to restart it
You could try this. In this scenario, the program will wait for you to push enter to quit. Now you can run the program as before. julia programfile.jl
.
using Plots
arr = [1.2, 1.4, 1.5, 1.1]
x = [1, 2, 3, 4]
p = scatter(x, arr)
display(p)
println("Press the enter key to quit:")
readline()
We do not usually recommend executing a Julia program from the command line like that during development because you will incur latency each time you run it.
It is not clear to me how you are trying to redisplay the plot or replot. It sounds like you may be closing the window that pops up and that you are not using VSCode.
using Revise, Plots
function makeplot()
arr = [1.2, 1.4, 1.5, 1.1]
x = [1, 2, 3, 4]
p = scatter(x, arr)
display(p)
return p
end
p = makeplot()
if !Base.isinteractive()
println("Press the enter key to quit:")
readline()
end
To redisplay the plot in interactive mode,
julia> display(p)
To replot, try this:
julia> p = makeplot()
There is some function to force a new window in thr default GR backend.
Anothe alternative would be to try Makie.jl
I tried the first example of Makie using CairoMakie, with all the different procedures written above, with and without VSC terminal.
using CairoMakie
f = Figure(backgroundcolor = :tomato)
Nothing shows
Posting the output of:
versioninfo()
is useful many times for diagnostics.
Returned items in the Julia REPL are automatically passed to the display
function, which causes plots to show up as separate windows. In order to display a plot in this context, you should pass the plot object (for Plots.jl
) or the figure (for Makie.jl
) to display
.
Makie also allows you to wait till the screen is closed by following this pattern:
f = Figure(...)
# do things
screen = display(f)
wait(screen)
# do whatever you want after the screen is closed
Did you try VSCode with Plots.jl using the integrated REPL?
@mkitti I’m trying with the integrated repl, even if i would like to not use it.
This doesn’t change anything.
@asinghvi17 it doesn’t work, I attach a screen
this is the version @Dan
julia> versioninfo()
Julia Version 1.10.2
Commit bd47eca2c8a (2024-03-01 10:14 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 8 Ă— Intel(R) Core(TM) i7-4720HQ CPU @ 2.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, haswell)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Isn’t there a simple command, like python, which plots everything I say the program to plot?
We have multiple cascading problems at the moment with the execution environment that I’m trying to disentangle.
Potential issues:
Julia is exiting immediately after showing the plot. This is what the various -i
, ,readline()
, and wait
commands are trying to solve.
There is a problem with Plots.jl or the GR.jl backend
There is a problem with Makie.jl or the CairoMakie.jl backend.
The screenshot is helpful. From this I can determine you are not using the integrated REPL. Rather you are using the integrated terminal, starting Julia from there, which will not achieve the desired effect.
To start the REPL integrated with the julia-vscode extension press Alt+J Alt+O as described here:
https://www.julia-vscode.org/docs/stable/userguide/keybindings/
You can then select code you want to execute and press Ctrl-Enter.
What we are trying to achieve is something that looks like this screenshot.
I’m an hour from putting together a demonstration video for you. Just to illustrate this.
I actually noticed that if I run the code normally, there is an instant when the color tomato is shown.
This is the REPL screenshot:
The only real error is the last one in the terminal. The other ones were me, trying to understand how the REPL works
If you are really against interactive use, then you may want to just save
the figure to disk at the end of your script. Then you can open and view the figure externally to Julia.
I surely want to save it when time comes, but before doing so i want to check everything is ok.
In this context, with CairoMakie.jl, the wait
function does not apply. This is applicable with other Makie.jl backends such as GLMakie.jl.
CairoMakie.jl works by generating an image and saving it. In your current mode, it is saving it to a temporary file.
Here’s a simple script close to what you were originally trying to achieve.
using CairoMakie
begin
arr = [1.2, 1.4, 1.5, 1.1]
x = [1, 2, 3, 4]
p = scatter(x, arr)
display(p)
if !Base.isinteractive()
println("Please press any key to continue:")
readline()
end
end
This is meant to work inside and outside of VS Code. I used the begin
and end
blocks to make easier to use in VS Code via Ctrl-Enter.
You can also save the figure out using
save("test.png", p)
I get the following plot.
I created a short video on plotting via the REPL outside of VSCode using Plots.jl:
Here’s a sequel showing the missing plots problem that you encountered.
I added a 3rd video showing plotting with GLMakie.jl in the Julia REPL and via a script.
ah CairoMakie won’t display since it’s a vector backend - use GLMakie or WGLMakie for this purpose.