我正在学习 PlotlyJS.jl 包,并且我注意到仅当我使用 REPL 时才会出现绘制函数的窗口 - 当我使用 julia test.jl
命令启动程序时,带有图表的窗口不显示。这种行为的原因是什么?我可以做些什么来使窗口出现在 REPL 的“外部”吗?
最佳答案
来自 ChrisRackauckas 在 a thread of the Julia forum 中的回答:
(...) 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.
这解释了为什么当您从 REPL 而不是从脚本运行 plot()
函数时会出现绘图窗口。脚本的默认行为是不显示任何内容,包括绘图。为了在运行脚本时显示绘图窗口,您必须将 plot()
命令包含在 display()
函数中,如下所示:
x = 0:10
display(plot(x, x.^2))
关于Julia - PlotlyJS 绘图仅适用于 REPL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40834142/