re-display a cell?

Hi!

If I’ve created and displayed a plot in one cell, as in

aplot = Plot.plot({
  marks: [
    Plot.line([[1,0],[0,1]])
  ]
})

How can I re-display the same plot in a later cell? A cell just declaring the plot again like this:

aplot

causes the first cell to show the raw object rather than the display of the plot.

(Why do I want to show the same plot at two places in the same notebook? Long story.)

This discussion post also mentions this question, but it doesn’t actually show how to write code that displays a cell’s output in two different places. The notebook it links to went right over my head! Deep stuff!

(Perhaps that discussion and the notebook it links to don’t show how to do it because it’s impossible?)

2 Likes

You can always clone it; to do so, try this:

aplot.cloneNode(true)

I guess this is really a more general Javascript in the browser thing so you can read more about it here:

2 Likes

I prefer rearranging into a function if reuse is needed

aplotBuilder = () => Plot.plot({
  marks: [
    Plot.line([[1,0],[0,1]])
  ]
})

This is how the standard Inputs are distributed.

4 Likes