I want to plot a huge amount of binary data (a 2700x2001 matrix, 5402700 points), and for that I am using the Graphics[Raster[]] function. With just that command, namely


gives the following graph

enter image description here

Now, I use the same code but with another colour function


What I see is just a white square. If I try to save that "graph" and as I save it to .jpg, then I get the right image

enter image description here

But not when I save it to .pdf, the desired format. I just get a blank PDF.

On the other hand, if I choose to plot less points (2500x2001=5002500), then the graph is shown correctly and I can export it to .pdf without any issue.

Therefore I have two questions: Why does this happen? (I guess it has something to do with the maximum number of points that the laptop can somehow resolve or store), and how to solve this issue and obtain the desired graph exported in .pdf format?

EDIT: Although it has been suggested that this issue is the same as in here, I believe that the specific problem in both cases is not the same, since in the other question, when using ArrayPlot and MatrixPlot with nonzero matrices they obtain the appropriate output, as opposed to here.

Thank you for your time.


1 Answer 1


Something seems off in the use of ColorFunction by Raster here. This seems akin to the problem reported before in similar matrices containing $(0,1)$ entries (see e.g. MatrixPlot ignores ColorFunction for 0 matrices and ArrayPlot with a user-defined color function is misbehaving).

In your case, ArrayPlot seems to work as desired using this synthetic data set:

data = SparseArray[{i_, j_} /; And @@ Thread[300 <= {i, j} <= 1000] -> 1, {2700, 2001}, 0];

In fact, I obtain the following plot:

ArrayPlot[data, ColorFunction -> "TemperatureMap", Frame -> False]

Mathematica graphics

  • $\begingroup$ ArrayPlot also works with the particular example I was dealing with. Thanks for the advice! $\endgroup$
    – Alex
    Commented Jun 6, 2016 at 12:57

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.