Search code examples
matlabmatrixplotdensity-plot

MATLAB: Density-time Plot


I have 11 1x50 matrices that contain densities. The first looks like [20, 20, 20... 20] and represents time=0. The second looks like [20, 19, 22,..], etc. and represents time=100. These continue to vary until t=1000.

What I'm hoping to do is to create a plot with the elements' position on the x-axis (50 positions for the 50 pieces of data in each) and time (0-1000) on the y-axis. Ideally, I'd like the plot to be completely filled in with color densities, and a colorbar on the side that shows what densities the color range represents.

Any help would be greatly appreciated!

Sort of inspired by: http://www.chrisstucchio.com/blog/2012/dont_use_scatterplots.html


Solution

  • Assuming you have (or can arrange to have) all those vectors as columns of a 11x50 matrix:

    A = randi(100, 11,50); %//example data
    

    you can just use

    imagesc(1:50, 0:100:1000, A)
    colorbar
    axis xy %// y axis increasing, not decreasing
    

    Example:

    enter image description here