I have a page containing a plot.ly plot, that I want to write data to a few times, overwriting what was there before.
I can't find a way to remove all traces from my plotly.js plot, and just replotting adds the data without removing the old.
If you want to hide the trace names in a box chart, you could hide the axis' labels by using showticklabels = F . In the example below the trace name is also hidden in the hover labels by setting hoverinfo = 'x' .
Adding Traces New traces can be added to a plot_ly figure using the add_trace() method. This method accepts a plot_ly figure trace and adds it to the figure. This allows you to start with an empty figure, and add traces to it sequentially.
A plotly. graph_objects. Image trace is a graph object in the figure's data list with any of the named arguments or attributes listed below. Display an image, i.e. data on a 2D regular raster. By default, when an image is displayed in a subplot, its y axis will be reversed (ie.
Plotly Express is a built-in part of the plotly library, and is the recommended starting point for creating most common figures. Every Plotly Express function uses graph objects internally and returns a plotly.graph_objects.Figure instance.
There's two ways of doing this, both listing in the plotlyjs function reference page.
Option 1 (tell plotly to delete the trace(s) in question):
Plotly.deleteTraces(graphDiv, 0);
where the second argument is the trace index of the trace to delete. Note that this second argument can also be an array of indices allowing you to delete multiple traces at once.
Option 2 (tell plotly to make a new plot with new data):
Plotly.newPlot(graphDiv, data, layout);
where the arguments are the same as for Plotly.plot
. This creates a new plot drawing only the data sent in the second argument. More precisely, Plotly.newPlot
is idempotent whereas Plotly.plot
isn't.
you can remove the last trace, and the previous one, and so one until the last one :
while(graphDiv.data.length>0)
{
Plotly.deleteTraces(graphDiv, [0]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With