In [1]:
using PlotlyJS
In [2]:
trace1 = scatter(;x=1:4, y=[0, 2, 3, 5], fill="tozeroy")
trace2 = scatter(;x=1:4, y=[3, 5, 1, 7], fill="tonexty")
p2 = plot([trace1, trace2], Layout(height=200, width=330))
Out[2]:
In [3]:
# second trace will turn pink
restyle!(p2, 2; marker_color="magenta")
In [4]:
# watch both markers change to squares
restyle!(p2, [1,2]; marker_symbol="square")
In [5]:
# simpler method without passing [1,2]
restyle!(p2; marker_symbol="star-triangle-up-open")
In [6]:
relayout!(p2; width=400, height=250)
In [7]:
relayout!(p2; title="Interactively controlled!")
In [8]:
trace3 = scatter(;x=1:4, y=rand(1:10, 4), fill="tozeroy")
addtraces!(p2, trace3)
In [9]:
# Add one to the front of the stack. will appear on bottom of legend
# Notice it
trace4 = scatter(;x=1:4, y=rand(1:10, 4), fill="tozeroy", marker_color="yellow")
addtraces!(p2, 1, trace4)
In [10]:
deletetraces!(p2, 4)
In [11]:
deletetraces!(p2, 1) # back to where we started :)
In [12]:
# swap the order of the traces (move trace at index 1 to the back)
movetraces!(p2, 1)
In [13]:
# swap them back
movetraces!(p2, [2, 1], [1, 2])
Notice that the plot object also changed so everything was kept in sync:
In [14]:
p2.plot.layout
Out[14]:
In [15]:
p2.plot.data[1]
Out[15]:
For each of the functions restyle!
, relayout!
, addtraces!
, deletetraces!
, and movetraces!
there is also a non-mutating version with the same name, but without the !
. These will create a copy of the underlying data, perform the given transformation, and return a new object.
You can tell the object is new because a new plot appears:
In [16]:
p3 = relayout(p2; xaxis_title="new title")
Out[16]:
In [ ]: