Re: Mathematica: How to update the same plot once it is created?



On Jan 13, 3:49 pm, "Nasser Abbasi" <n...@xxxxxxxxx> wrote:
This seems like it should be easy to do, but I really think this is
impossible to do in Mathematica.

Here is the problem: I make a plot. The plot is shown and displayed ok. Now,
later on, I want to update the same plot, but NOT create a separate plot.
There does not seem a way to do this.

Here is an example:

p=Plot[Sin[x],{x,-Pi,Pi}]
...
...
... Now, I want to make changes to the above plot
.... say I want to add something to it, or redraw it
.... how??

I do not want to create a new plot window (i.e do not want to create a new
Cell), I want the updates to go to the plot display above, i.e. physically
the same plot window in the same cell as it was, and not create a new plot
window.

I am trying to do some simulation (discrete event simulation, one queue one
server basic model) where I want to update the same plot as time ticks go
by. and I need to be able to update the same plot window from different
places in the code (as the system state changes) and not have to create a
new plot window each time.

I do not want to use Manipulate or Animate as they do not fit what I am
trying to do, I need to be able to better control this, and I do not want to
combine the plots and display them at the end, I need to update the plots
right away.

The above sort of thing is easy to do in Matlab and R (is it possible to do
in Maple?) but I am surprised how hard it is to do in Mathematica.

I hope I am overlooking something simple, and someone has a solution to this
one. I looked at may be using SelectionMove[] to select the cell where the
plot is in and such tricks, but I am not sure yet, I am still trying to see
if this will work.

You could always use a Dynamic plot. Something like this, maybe?

a = b = c = 1;

Dynamic[Plot[{a Sin[x - a], b Sin[x - b], c Sin[x - c]}, {x, 0, 10},
Frame -> True, PlotStyle -> Thick]]

Column[{Button["a", a++], Button["b", b++], Button["c", c++]}]

(In this case Plot[...] is re-evalauted any time a/b/c are changed,
but in such a way that the new graphic replaces the old graphic.)

Brett Champion
.