This is probably a fairly trivial question, yet I have been unable to find an answer - help would be much appreciated! :)

I am trying to plot a 28 x 28 matrix (tabulated data given here), containing continuous pixels values on the interval [0;1]. I am using MatrixPlot and ColorFunction -> GrayLevel, so that 0 comes out as black and 1 as white, and all values inbetween will cover the gray spectrum. MatrixPlot produces a lovely 28 x 28 matrix plot - however, for some reason it uses a medium gray for 0, and scales the remaining values accordingly on the gray spectrum, with 1 still being white.

This is the code used:

input1 = Get["http://pastebin.com/raw.php?i=PP2t8tp6"];
MatrixPlot[input1, ColorFunction -> GrayLevel, Mesh -> None, AspectRatio -> 1/1, ImageSize -> 300]

The resulting image:

enter image description here

Adding a file extension (.dat, .csv, .txt) and adding separators made no difference - I also tried forcing the color spectrum with ColorRule, but no luck.

  • $\begingroup$ I have nowhere to upload the file for linking - but the data is of the form described above, outputted from my program with simple spaces " " as separators and '\n' as newline. :) $\endgroup$
    – Nielsen
    Commented Apr 28, 2014 at 12:43
  • 1
    $\begingroup$ Please prodive your inputfile, it will be easier for everyone. You can paste it in your question or on pastebin. The simplest way is to copy/paste input1 on pastebin. $\endgroup$
    – Öskå
    Commented Apr 28, 2014 at 12:49
  • $\begingroup$ Seems a little space consuming - but I've added it to the post. :) $\endgroup$
    – Nielsen
    Commented Apr 28, 2014 at 12:54
  • 1
    $\begingroup$ Try ColorFunctionScaling -> False. $\endgroup$
    – William
    Commented Apr 28, 2014 at 12:57
  • $\begingroup$ Spot on, that worked - thank you very much! :) $\endgroup$
    – Nielsen
    Commented Apr 28, 2014 at 12:59

1 Answer 1


You need to prevent scaling of the data with the option ColorFunctionScaling -> False

data = Get["http://pastebin.com/raw.php?i=PP2t8tp6"];
MatrixPlot[data, ColorFunction -> GrayLevel, 
 ColorFunctionScaling -> False]

Mathematica graphics


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.