PyPlot "plot()" 函数在 Ubuntu 16.04 上的 julia 0.4.5 中失败

PyPlot "plot()" function fails in julia 0.4.5 on Ubuntu 16.04

我正在使用一个程序,该程序旨在采用一些参数并使用遗传算法根据所述参数优化五层镜面涂层。就在终止之前,该程序旨在显示反射镜在 运行ge 波长范围内的理论反射率图。程序的最后四行是:

plot(lam,rf)
xlabel("wavelength(AA)")
ylabel("reflectivity")
title("Broadband reflectivity")

当我从命令行 运行 执行此操作时 (sudo julia Broadband.jl),绘图从不显示;我在那里放了几个 println() 函数,在 plot(lam,rf).

之前和之后都有输出

也许 st运行 最重要的部分是我复制了整个代码,将其粘贴到终端并 运行 直接从 julia (julia> [ENTIRETY OF .JL FILE]),并显示情节。有谁知道我错过了什么?

请注意 PyPlot README 中的以下内容:

If you use PyPlot from an interactive Julia prompt, such as the Julia command-line prompt or an IJulia notebook, then plots appear immediately after a plotting function (plot etc.) is evaluated.

However, if you use PyPlot from a Julia script that is run non-interactively (e.g. julia myscript.jl), then Matplotlib is executed in non-interactive mode: a plot window is not opened until you run show() (equivalent to plt.show() in the Python examples).

因此,您必须从命令行调用 show() 以便在 运行 时显示绘图。