Message Boards Message Boards


How do you display a graphic in a new window -- repeatedly?

Posted 4 years ago
4 Replies
2 Total Likes

I have been looking for the syntax needed to display a graphic (this one produced by ListPlot) in a new window, and do so repeatedly, each time replacing the new window contents without creating an additional new window. I would like also to generate the window at a particular size, and if it is moved while the repeated refresh is occurring, have it stay where it's placed.

Any help is appreciated!

4 Replies

Here's one way to do it: First, create your output window like this:

CreateDocument[Dynamic[theGraphic], WindowSize -> {500, 500}];

CreateDocument has a lot of options (use Options, not all of them are listed in the Documentation article), I just added WindowSize here because you asked about it. Maybe you can set the window position as well, although I can't seem to find it right now. (But that would ensure that the output window can't be moved.)

Anyway, the output window will now update theGraphic dynamically, so you can do this:

theGraphic = ListPlot[RandomReal[{0, 1}, {20, 20}]];

Alternatively, if you want to change the behaviour of all Graphics objects, you could do this:

$Post = (If[TrueQ[Head[#] == Graphics], theGraphic = #;, #] &);

And now an expression like ListPlot[RandomReal[{0, 1}, {20, 20}]] will change theGraphic and therefore trigger an update in your plot window.

I'm not sure if this is what you were looking for... It's a rather clumsy solution but maybe it'll get you started.

Thanks, Bianca -- That works!

Actually there is a straightforward way to change the behavior of all Graphics objects (including those which do not go to the $Output channel): simply to define

$DisplayFunction = ((theGraphic = #; #) &);

An alternative to Dynamic solution is to use the second argument of CreateDocument:

obj = CreateDocument[];
$DisplayFunction = ((CreateDocument[#, obj]; #) &);
Do[ListPlot[Prime[Range[n]], Filling -> Axis], {n, 25, 50}]
Posted 4 months ago

Thanks. Could I plot many figures in a new window. In the suggested way the only one figure (the last) is displayed.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract