1
$\begingroup$

I have a data file consists of evolving 2d square array over time. The first block of the 16*16 square array contains the initial values on each of the 256 points. Then the 2nd block is the square array containing the evolved values on each of the 256 points after 1 unit of timestep. And so on... My aim is to generate an animation such that one can see how the values of the points of 2d square array are evolving with time. (A real example could be if there is 16m * 16m water surface, and the values of each point is the height of the water surface, and I would like to see how this water surface evolves with time) Please let me know if you have any suggestions, thank you!

The following is an example of how the data file consists of evolving 2d square array looks like: enter image description here

$\endgroup$

1 Answer 1

3
$\begingroup$

Here's one way: First, we create a small dummy file since you didn't provide one:

file = Export[CreateFile[], "
  1,1
  1,1
  
  2,1
  1,2
  
  2,2
  2,2
  ", "Text"]

Now we can import the data and create the plot:

data = SequenceSplit[
   Import[file, "CSV"],
   {{}}
   ];
Animate[ArrayPlot[data[[i]], PlotRange -> Max@data, PlotLegends -> BarLegend@Automatic], {i, 1, Length@data, 1}]

enter image description here

As you can see, we first import the data as "CSV", which results in {} for the gaps between blocks. We use SequenceSplit to break the blocks apart, and then use Animate with ArrayPlot to get the plot as a function of time.

$\endgroup$
1
  • $\begingroup$ Yes this works! Thank you so much! :D $\endgroup$
    – Kaiggff
    Jul 21, 2021 at 4:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.