Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
    
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. :) –  nielsen Apr 28 at 12:43
1  
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. –  Öskå Apr 28 at 12:49
    
Seems a little space consuming - but I've added it to the post. :) –  nielsen Apr 28 at 12:54
1  
Try ColorFunctionScaling -> False. –  billisphere Apr 28 at 12:57
    
Spot on, that worked - thank you very much! :) –  nielsen Apr 28 at 12:59

1 Answer 1

up vote 6 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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