Julia - PlotlyJS 绘图仅适用于 REPL

标签 julia plotly

我正在学习 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/

相关文章:

python - Plotly Express 散点调整点大小

python - plotly.express - 像 sns.lineplot 中的置信区间

julia - Julia 散点图中的大小和颜色

R仅将颜色填充到下一个y的上值

statistics - Julia 的移动平均线

coding-style - Julia 函数命名 : When should I append a bang?

python - 来自 Wavefront OBJ 文件的 Plotly Mesh3d 绘图

javascript - plotly js : location and length of color scale in heatmap

algorithm - julia 中排名不满的矩阵的尺寸缩减

string - 在 Julia 中搜索字符串并返回条件输出的最佳方法?