I have compiled data about the evolution of a function with time and the data looks something like this.

I wanted to plot this data in the form of a density histogram such that every row represents one of the four states and every column represented number the observances of the object in one of the four states at a particular time. The end result should appear something like.enter image description here

I first tried to use the DensityHistorgram but I was unable to put discrete data into it and the documentation did not mention how I could do so. I would be very grateful if anyone could tell me how to plot such a function.

Note: I apologize for putting the data as an image. If you can plot it for any simple data I could use that forward in my work. So, please feel free to use the simplest of data. I only wish to understand how data can be plotted in this manner.

  • $\begingroup$ tried MatrixPlot? $\endgroup$
    – kglr
    Commented May 21, 2019 at 19:07
  • 1
    $\begingroup$ May you paste the data as code instead of an image. $\endgroup$
    – Edmund
    Commented May 22, 2019 at 0:01

1 Answer 1


You can use MatrixPlot:

data = Sort /@ RandomReal[1, {4, 20}];

MatrixPlot[data, AspectRatio -> 1/4,  ColorFunction -> "Rainbow", ImageSize -> Large]

enter image description here


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.