question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plotly#redraw (1.20.4.min.js) appears to not clean up properly

See original GitHub issue

I have the following, simple code (also see attached zip for standalone:

<!doctype html>
<html>
<head>
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
  <title>plot.redraw multiple axes</title>
  <script src="plotly-1.20.4.min.js"></script>
</head>
  <body>
    <div id="myDiv1"></div>
    <div id="myDiv2"></div>
    <script>
      var trace1 = {
        x: [1, 2, 3],
        y: [40, 50, 60],
        name: "yaxis data",
        type: "scatter"
      };
      var trace2 = {
        x: [2, 3, 4],
        y: [4, 5, 6],
        name: "yaxis2 data",
        yaxis: "y2",
        type: "scatter"
      };
      var layout1 = {
        title: "Remove yaxis, use redraw()",
        yaxis: {title: "yaxis title"},
        yaxis2: {
          title: "yaxis2 title",
          titlefont: {color: "rgb(148, 103, 189)"},
          tickfont: {color: "rgb(148, 103, 189)"},
          overlaying: "y",
          side: "right"
        }
      };
      var data = [trace1, trace2];
      Plotly.newPlot("myDiv1", data, layout1);
      Plotly.newPlot("myDiv2", data, layout1);

      setTimeout(function() {
        delete layout1.yaxis2;
        delete trace2.yaxis;
        var plot = document.querySelector("#myDiv1");
        // plot.layout = layout1;
        // redraw appears to not clean out the old data
        Plotly.redraw("myDiv1");

        var layout2 = {
          title: "Using Plotly#newPlot seems to work",
          yaxis: {title: "yaxis title"}
        };
        // this works as expected
        Plotly.newPlot("myDiv2", data, layout2);

      }, 2*1000);

    </script>

  </body>
</html>

What I get is the following: screen shot 2016-12-02 at 14 26 34

As you can see, the upper plot is being updated with Plotly#redraw while the lower plot is updated using Plotly#newPlot. I would expect those two invocations to produce the same result. However, in the one using Plotly#redraw, it appears as thought the previous 2nd y-axis and the associated trace is not cleaned up properly. You can also see that when the mouse is hovered over the trace, the ‘old’ trace is not (correctly so) taken into account, i.e. no hover-text appears over the ‘old’ trace.

I have verified this behaviour on a Mac OS 10.10.5 and the following browsers:

  • Chromium, Version 55.0.2876.0 (64-bit)
  • Chrome, Version 54.0.2840.98 (64-bit)
  • Safari, Version 9.1.2 (10601.7.7)
  • Firefox, Version 50.0.2

plotly-multiple-axes.html.zip

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
etpinardcommented, Nov 2, 2017

@czellweg redraw will soon be deprecated and be replaced by https://github.com/plotly/plotly.js/issues/1850 - so don’t expect this ticket to be resolved anything soon.

In the meantime, I suggest rewriting your logic using Plotly.restyle, Plotly.relayout or Plotly.update.

1reaction
rreussercommented, Dec 2, 2016

Yeah, definitely seems like a reasonable workaround. (Also, of course only one of two plots actually needs a clone.) I think there was a bit of discussion related to this, so I’ll check around and get @etpinard’s input before digging further at the moment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

plotly.js-gl2d-dist-min | Yarn - Package Manager
Ready-to-use minified plotly.js gl2d distributed bundle. Contains trace modules heatmapgl , parcoords , pointcloud , scatter , scattergl and splom ...
Read more >
CHANGELOG.md · res5692-no-longer-latest-cdn · mirrors / plotly ...
Open-source JavaScript charting library behind Plotly and Dash Github ... Avoid infinite redraws to compute autorange for "inside" tick labels on the ...
Read more >
Source - GitHub
Fix automargin to update axis titles in redraws [[#6312](https://github.com/plotly/plotly.js/pull/6312)] - Fix exporting patterns with transparent color ...
Read more >
CHANGELOG.md · v1.39.2 · publicRepo / plotly.js - GitLab
We made this change to clean up some of the Plotly.react internals. ... npm install do not get the wrong mapbox-gl version message...
Read more >
plotly Changelog - PyUp.io
4. Not secure. Updated - The documentation of the API https://plot.ly/python-api-reference/ now
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found