Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly: add_trace in a loop

Tags:

I'm trying to add_trace ad each loop, but I get only one plot with multiplies lines on over each other.

mean <- -0.0007200342
sd   <- 0.3403711
N=10
T=1
Delta = T/N

W = c(0,cumsum( sqrt(Delta) * rnorm(N, mean=mean, sd=sd)))
t <- seq(0,T, length=N+1)

p<-plot_ly(y=W, x=t)

for(i in 1:5){

  W <- c(0,cumsum( sqrt(Delta) * rnorm(N, mean=mean, sd=sd)))
  p<-add_trace(p, y=W)

}
print(p)

enter image description here

like image 359
sparkle Avatar asked Dec 09 '15 18:12

sparkle


People also ask

What is Add_trace in Plotly?

Adding Traces To Subplots If a figure was created using plotly. subplots. make_subplots() , then supplying the row and col arguments to add_trace() can be used to add a trace to a particular subplot.

What are traces in Plotly?

From the Plotly website: “A trace is just the name we give a collection of data and the specifications of which we want that data plotted. Notice that a trace will also be an object itself, and these will be named according to how you want the data displayed on the plotting surface.”

What is Plotly Graph object?

What Are Graph Objects? ¶ The figures created, manipulated and rendered by the plotly Python library are represented by tree-like data structures which are automatically serialized to JSON for rendering by the Plotly. js JavaScript library.


2 Answers

The plot_ly and add_trace functions have an evaluation = FALSE option that you can change to TRUE, which should fix the scope issues.

like image 123
Perry Kuipers Avatar answered Sep 21 '22 04:09

Perry Kuipers


Use evaluate = TRUE in add_trace.

like image 40
TheDimLebowski Avatar answered Sep 19 '22 04:09

TheDimLebowski