Whether Plots.scatter (or anything else) displays the plot or not seems to depend on the code that is not related to plotting. Following code does not display the plot, but with a line of println commented out, it displays the plot correctly. I tested these on Julia version 0.5.0 and Plots version 0.10.1.
I also found that the version correctly working above also fails (does not show the plot) when run from the command line...
import Plots
function main()
Plots.plotly()
xs = collect(1:0.1:4)
ys = xs .^ 2
Plots.scatter(xs,ys)
# When commented out, the graph shows up.
println("Hey")
end
main()
Plots are not displayed just because there is a plot command somewhere. That would be very annoying if you want to incrementally build a plot. Instead a plot is shown when the REPL tries to display the generated plot object. This is exactly the same as the REPL not printing the xs and ys in your function.
For example:
import Plots
function main()
Plots.plotly()
xs = collect(1:0.1:4)
ys = xs .^ 2
p = Plots.scatter(xs,ys)
println("Hey")
return p # Return the plot object
end
main()
Alternatively, you can call display(Plots.scatter(xs,ys)) to make it display your plot object. This would work in REPL.
Oh, it's my bad! Thanks, I figured out it is stated in the doc.
https://juliaplots.github.io/basics/
The graphic is not shown implicitly, only when "displayed".
https://juliaplots.github.io/output/
A Plot is only displayed when returned (a semicolon will suppress the return), or if explicitly displayed with display(plt), gui(), or by adding show = true to your plot command.
Most helpful comment
Alternatively, you can call
display(Plots.scatter(xs,ys))to make it display your plot object. This would work in REPL.