# Update or Animate an ArrayPlot or MatrixPlot?

I am trying to add new row or column or points to a 2D plot as I keep generating the values. The trick is by using this method I will not be required to store the big array or matrix and will be helpful in plotting suppose $50000\times 4000$ array size. By the end of the loop, I want to the get 2D plot without storing array or matrix. See the example code.

This could be implemented in MATLAB as initializing figure with some size and properties, hold on and adding each row or data point as generated.

a = Table[{0}, {5000}, {6000}]; (* initialize*)

For[k = 1, k <= 5000, k++,

line = 2*k*Range[1,6000]; (* random way of getting data value at (k,t) index*)

(* here write graphics command to add new row points at index (k,t) to the 2D plot*)

]

• Did you succeed in plotting your 50000x4000 array with Matlab ? If so you have enough memory to do the same with Mathematica. The Show approach can deal with that, though the solution proposed below do not show how to use it with arrays. I might have a solution for you. Nov 14 '15 at 16:11
• @SquareOne I am able to Animate however as you mentioned, not enough memory to plot large array. I am still looking for the solution. Nov 15 '15 at 17:01
• I don't understand: 1/ what do you exactly Animate ? 2/you did that (Animate) with Matlab or Mathematica ? Nov 15 '15 at 17:22

A possible solution is to not store the data, but rather to store plots of the data at each step. These plots can be combined together using Show, but the data that were used to generate them can be discarded.

xmin = 1;
xmax = 5;
xstep = 1;
plotList = {};

Monitor[
Do[
AppendTo[plotList,
Plot[x Cos[x],
{x, 0 + (i*2 Pi), 2 Pi + (i*2 Pi)},
PlotStyle -> ColorData[i, "ColorList"]]];
Pause;
, {i, xmin, xmax, xstep}];
, Show[plotList, PlotRange -> All]
] The final plot (shown here) demonstrates that the different segments were plotted with different colors:

Show[plotList, PlotRange -> All] • I'd probably be using Table[] here. Nov 7 '15 at 22:14
• Table for what? Data generation? e.g. ListPlot? Nov 7 '15 at 22:31
• Thank you. I got some idea. I am basically looking for output similar to Matrix or Array plot, however by adding each column to the 2D figure as I don't have matrix available at one time. May be ListDensity or scatter functions can be used with this solution? Nov 7 '15 at 22:45
• I mean, instead of a Do[] loop with AppendTo[], I'd use Table[] instead: plotList = Table[Plot[x Cos[x], {x, 0 + (i*2 Pi), 2 Pi + (i*2 Pi)}, PlotStyle -> ColorData[i, "ColorList"]]], {i, xmin, xmax, xstep}]; Then, generate the animation with Animate[Show[Take[plotList, k], (* options *)], {k, 1, Length[plotList]}]. But if the purpose was to be able to use Monitor[], then yes, this is okay, but I'd still cast a jaundiced eye over AppendTo[]. Nov 7 '15 at 22:47
• @J.M. Yes, this is preferable if all the data are available at t=0, and the number of additions to the plot are known. I do this sort of thing that I have shown in e.g. monitoring MCMC evolution. Nov 7 '15 at 22:52