Message Boards Message Boards

Clear output between successive prints of ListLinePlot - workaround needed

Posted 1 year ago

My notebook is in three "parts". The first "part" (all collapsed cells) sets up all the preliminaries. The second part display two comboboxes and a button. The code in the button (i) calls a module in the third part (which does some calculations and sets up the plot and returns the plot) then (ii) prints the returned plot to screen. This is all fine as shown here (after the button has been clicked once): enter image description here

The problem is that when the button is clicked for the second time the next plot appears after the first plot - that's obvious and expected and AFAIK there is no way of clearing the first plot.

As a possible workaround (and just thinking aloud again) I was wondering if there might be a way to display the plots in a grid or graphicsgrid (one row, one column) which could be cleared between plots?

Or, specify the content of the grid as a dynamic variable containing the output of ListLinePlot, for example myPlot = ListLinePlot[....] (might have to do a conversion to a graphics object??)

I'll start experimenting but if anybody has any thoughts on this, I'd be very happy to hear them.

POSTED BY: Paul Newton
3 Replies
Posted 1 year ago

In response to the comment above, the relevant section of makePlot[] looks like this:

result = ListLinePlot[.....]
Return[result]

and makePlot[] is called in this section of code (aciid1 and acid2 are the source data for the PopupMenus)

Style[Dynamic[$Version], DynamicUpdating -> True];
(*Dynamic[myPlot]*)
myPlot = makePlot[];
Grid[{{"First acid", PopupMenu[Dynamic[acid1], menuData], 
   ""}, {"Second acid", PopupMenu[Dynamic[acid2], menuData], 
   Button["Display", myPlot = makePlot[]]}, {"", Dynamic[myPlot], ""}}]
(*Dynamic[myPlot]*)

I have used Dynamic[myPlot] in the third row of the grid, but the two commented lines show that it could also be used before or after the code which creates the PopupMenus and Button.

myPlot = makePlot[] is called for the initial display and then called each time the button is clicked

If asked, I can attach the entire notebook.

POSTED BY: Paul Newton

Welcome to Wolfram Community! Please make sure you know the rules: https://wolfr.am/READ-1ST

Please provide your trials in terms of Wolfram Language code. This will make it easier for other members to help you.
Showing the actual code is necessary besides describing it with text.
Please use one of the methods described in the rules above.

POSTED BY: Moderation Team
Posted 1 year ago

I was not all hopeful that I was thinking along the right lines, hence my question, but as it turns out this was far simpler than I anticipated. It's working like a charm.

Still, somebody might find this useful (I have seen other posts about clearing output ...)

I'd be happy to provide more detail if anybody is interested.

POSTED BY: Paul Newton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract