Display Plots.jl plot in Juliabox


#1

I am using Plots.jl with PlotlyJS backend in Juliabox and I find myself in the situation of calling add_plot to add a trace at the time. I then call gui() at the end of the cell to display the plot. The following code used to work until a couple of weeks ago. It now works (in this minimal example) only if I remove gui().
In the code I have, it seems to work with gui only the first time the cell is executed, but not if I re-execute it. pyplot does not seem to show this problem, but pyplot doesn’t have remote interactivity.

using Plots
plotlyjs()

function add_plot()
    plot!(randn(10))
end

plot()
add_plot()
gui()

#2

I actually have no idea how gui windows are handled in JuliaBox. I would
expect this wouldn’t work… You should just return the plot object to the
jupyter cell.


#3

As in having the plot object as the last line in the cell? What about if the call to plot! is in a function?


#4

Both plot and plot! return a Plot object. Just make that object be
the last thing in the cell.


#5

PyPlot used from Plots does not need this: I can update a plot deep from a function, without returning it and it has not problem displaying the plot. It seems only related to PlotlyJS,


#6

what about using Plotly instead of PlotlyJS here?


#7

Same thing.
But the fix is easy (although not convenient): return the plot as the last statement in the cell, just what Tom said.

function add_plot()
    plot!(randn(10))
end

p = plot()
add_plot()
p

#8

For completeness… since plot! returns a Plot object, your (seemingly unnecessary but presumably as a minimal example) add_plot method will also return a Plot object. So add_plot() can be the last line of your cell.


#9

You are right. In the code, the add_plot returns nothing.