Why no canvas popping up with Plots

Hi every one I hope you can help me out. I’m new to Julia and new to vs code.
Running a simple program in vs code using plots, no plot pane shows up. If I run it in the julia terminal line by line it does show up but running the .jl file it does not show up.

using Plots
f(x) = sin(x)
plot(f, 0, 6.28292)
println(“Hello World”)

The program prints Hello World and pauses until I press a key. I installed plots and there is no error.
What have I done wrong?
Any help would be greatly appreciated,
Thanks,
Elisabeth.

Welcome to the Julia Discourse! Have a look here for tips on writing posts, in particular for formatting the code examples.

I think the problem is that in the terminal (REPL), the result of every line is automatically displayed, so when you run plot(f, 0, 68292) it shows the plot. But when you run a code block in VS Code it probably shows only the result of the last line (here the last line has no result: the println call writes the message to standard output but then it doesn’t return anything).

You can force the display of an intermediate result with the display function:

plt = plot(f, 0, 6.28292)
display(plt)

Thanks verry much for your reply. It feels good to know there are people out there that want to help me.
The code now looks like this and it still does not display a plot pane.

using Plots
f(x) = sin(x)
plt = plot(f, 0, 6.28292)
display(plt)

vs code gives a wavy line under “plot(f, 0, 6.28292)” saying : Possible method call error. Julia(incorrectCallArgs)

I tried copying examples from the reference page but they produce the same result.
Thanks for your help,
Elisabeth.

1 Like

I don’t use VSCode, so I can’t swear to this, but Plots · Julia in VS Code mentions that plots appear “in a new tab”. Are you missing the new tab, expecting a pop-up, perhaps?

I’m not able to reproduce your result with VS Code. All seems to be working fine for me:

What is your versioninfo()? Mine is

It is possible that the issue is not with Julia, but within VS Code; it appears from a search that other people are having similar problems; see here. The suggested solution by those in the thread is to disable the linter. Try that and see if that fixes the issue?

1 Like

Chat GPT to the rescue!
It told me that it needed a backend, whatever that is. I added Plotly and then it did open a pop-up but closed it again. so I added a while true line tot the code and now it opens the plot pane and keeps displaying it.

using Plots
f(x) = sin(x)
plt = plot(f, 0, 6.28292)
display(plt)

while true
end

Thank you all for your help. Now lets code.
Elisabeth.

None of that should be necessary. (The GR backend to Plots.jl is included by default. Other backends are optional.)

  1. Do you have the Julia extension for VSCode installed?

  2. How are you executing the code? Are you clicking the Play button?

  3. Have you tried closing and reopening VSCode?

  4. Is there a REPL window on the bottom with the julia> prompt? If so, what is the output of ] st?
    image
    image

1 Like

Yes.

No, I used ctrl f5, clicking the play button does pop-up a window within vs code. Hurray! Now it does not need the while loop any more.

I even tried rebooting my system.

Status C:\Users\guapo\.julia\environments\v1.9\Project.toml
[6e4b80f9] BenchmarkTools v1.3.2
[5ae59095] Colors v0.12.10
[28b8d3ca] GR v0.72.4
[9da27670] GameZero v0.3.1
[91a5bcdd] Plots v1.38.12
[27ebfcd6] Primes v0.5.3
[37e2e46d] LinearAlgebra

I think it popped up behind my vs code window and disappeared immediately.

Thanks a lot for your help,
Elisabeth.

Ah! Even though the name of this command is “Debug: Start Without Debugging”, it is part of the debugger and runs as a separate process in the debug console. When it finishes without error, it will close everything associated with that task including the plot windows.

You should use one of these commands instead (one of which is the Play button) to execute your code in the VSCode Julia terminal rather than the Debug Console.
image

I see that the first recommendation in the documentation is to run a file with Ctrl+F5 (probably where you got that from). I think the other paragraphs on that page about the REPL will be more helpful.

4 Likes

I think it’s telling that every time I’ve seen someone express this sentiment, they are being misled.

There are probably genuine use cases for ChatGPT, but when learning a new field or language you cannot judge the accuracy for yourself, and the AI will express nonsense just as confidently as it does real advice. Please don’t use ChatGPT as a tutor.

2 Likes