Javascript plotly:删除打印并在同一div中创建新打印

Javascript plotly:删除打印并在同一div中创建新打印,javascript,jquery,plotly,Javascript,Jquery,Plotly,我有一个plotly绘图,当数据发生变化时,我想删除该绘图并生成一个新的绘图。为此,我要这样做: $('#heatmap2').empty() 然后我重新生成我的情节。但当我这么做的时候,它就崩溃了: TypeError: Cannot read property 'textContent' of null at Array.Mo.text (plotly-latest.min.js:12) at Array.c.convertToTspans (plotly-latest.m

我有一个plotly绘图,当数据发生变化时,我想删除该绘图并生成一个新的绘图。为此,我要这样做:

$('#heatmap2').empty()
然后我重新生成我的情节。但当我这么做的时候,它就崩溃了:

TypeError: Cannot read property 'textContent' of null
    at Array.Mo.text (plotly-latest.min.js:12)
    at Array.c.convertToTspans (plotly-latest.min.js:31)
    at Array.Mo.call (plotly-latest.min.js:12)
    at l (plotly-latest.min.js:29)
    at Object.i.syncOrAsync (plotly-latest.min.js:30)
    at Array.r (plotly-latest.min.js:29)
    at Array.Mo.call (plotly-latest.min.js:12)
    at Object.s.draw (plotly-latest.min.js:29)
    at r (plotly-latest.min.js:28)
    at Object.w.colorbar (plotly-latest.min.js:38)
这是一个代码笔,显示在对div调用empty后,无法在其中创建另一个绘图:

这似乎没有抛出我得到的错误,但仍然没有创建情节

如何清除现有绘图,然后在中创建新绘图
同一个div?

回答我自己的问题:

如果我使用Plotly.newPlot而不是Plotly.plot,它会工作