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.
f(x) = sin(x)
plot(f, 0, 6.28292)
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,
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:
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?
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.
f(x) = sin(x)
plt = plot(f, 0, 6.28292)
Thank you all for your help. Now lets code.
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.
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.
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.