Yes, I see the problem you're having, in fact it's two problems. But since Petra's and my explanation attempts were unsuccessful so far, here's my last try and then I'll leave it at that.

The first problem is that since a heatmap looks 2 dimensional, you seem to assume it's based on a 2D array. It's not. You can see in the code above that plotHeatmap takes a 1d array. It's Data[rows*cols], not Data[rows][cols]. So your code will have a problem. The total memory size is correct, but you got wrong rows and columns.

Second problem is that you assume that a heatmap is written horizontally row by row. It's not. Non-square heatmaps are normally visualizing something over time, and the time axis is normally horizontal, so we want all elements belonging to a certain point in time to be written vertically in adjacent locations in the heatmap.

Check out the MVO script on Financial Hacker. There you can see how to generate a very long, non-square heatmap.