Does any know how to add multiple traces to a plot in Jupyter?
The following code works fine in Juno. It generates a series of offset sine waves in the same plot.
using GR
x=collect(0:0.1:2pi)
y=sin.(x)
plot(x,y)
for i=1:10
oplot(x,y.+i/10)
end
However, in Jupyter, no plot is produced. It seems anytime a cell ends in something other than the direct call for a plot, the plot does not show up when the cell is run.
Excellent! Is the line below storing an array of svg images in p? If not, is there a way to do that so that the array elements (svg images) can be referenced/used elsewhere?
This overwrites p with the plot so far on each loop. If you want all the intermediate plots you could set up an array and do p[i]=oplot(x,y.+i/10) but I’ve shut pc down for the night so can’t look for correct element type - let me know if you need this and I’ll look tomorrow
using GR
x=collect(0:0.1:2pi)
y=sin.(x)
p=Array{GR.SVG}(undef,1,11)
p[1]=plot(x,y)
for i=1:10
p[i+1]=oplot(x,y.+i/10)
end
display(p[1])
display(p[6])
display(p[11])
println("Hello")
A quick addition for the benefit of anyone reading this later. A plot statement seems to be needed before the loop so the oplot function has an image to write over.
using GR
x=collect(0:0.1:2pi)
y=sin.(x)
p=nothing
plot(x,y) #<===============
for i=1:10
p=oplot(x,y.+i/10)
end
display(p)
println("Hello")