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.

I'd like to export an output from MatrixPlot[], however, the output file size seems to depend on my specification of the ImageSize -> {..., ...}. How might I export a TIFF with all of the data in the $N \times M$ matrix being plotted? Presumably one could set the ImageSize to reflect the matrix dimensions, however, how would one appropriately pad for the axes and axes labels?

The command I'm using for MatrixPlot[] export is:

Export["MatrixExportFileExample.tiff",MatrixPlot[...]];
share|improve this question
    
Please do provide some sample code to illustrate your points of interest and show what you already tried. It seems also that you are posing two questions - please consider either detailing that or splitting into two questions. –  Yves Klett Jul 8 '13 at 5:50
1  
i.e. sample code which will actually run (... does not) ... –  Yves Klett Jul 8 '13 at 6:22
1  
You could create an Image from the data and export that instead. Image exports at 1-to-1 pixel size. –  Szabolcs Jul 8 '13 at 6:29
    
@Szabolcs Thanks - that's just what I was looking for. –  SqrtOfBlue Jul 8 '13 at 6:34
1  
Use the option PixelConstrained -> {1, 1}. –  Oleksandr R. Jul 8 '13 at 10:18
show 1 more comment

1 Answer

up vote 2 down vote accepted

I think what you are looking for is the PixelConstrained option of ArrayPlot, or understanding of its mechanism using Raster and Offset. With the default settings you will need Frame -> False to show all values (the frame overlaps the outer pixels).

data = CellularAutomaton[{1635, {3, 1}}, {{1}, 0}, 80];

ArrayPlot[data,
 ColorRules -> {0 -> Black, 1 -> Yellow, 2 -> Orange}, 
 PixelConstrained -> 2,
 Frame -> False
]

enter image description here

This makes every point on the plot a 2px by 2px square.
For full control this can be done manually with Raster and Offset:

data /. {0 -> {0, 0, 0}, 1 -> {1, 1, 0}, 2 -> {1, 0.5, 0}};
Graphics[Raster[Reverse @ %, {{0, 0}, Offset[{322, 162}, {0, 0}]}], 
 ImageSize -> {322, 162}, PlotRange -> {{0, 322}, {0, 162}}, Frame -> False, 
 FrameTicks -> None]

With either method you will find that adding frame ticks causes clipping as the ImageSize does not account for the label area. A solution is to specify the ImagePadding manually and include it in the ImageSize.

myPlot[data_, scale_Integer, pad_Integer:0, opts : OptionsPattern[]] :=
 With[{size = scale {#2, #} & @@ Dimensions@data},
  Graphics[Raster[Reverse @ data, {{0, 0}, Offset[size, {0, 0}]}], 
   ImageSize -> 2 + pad + size,
   PlotRange -> {{0, size[[1]]}, {0, size[[2]]}}, opts, 
   ImagePadding -> {{pad, 1}, {pad, 1}},
   PlotRangeClipping -> True, Frame -> True, 
   FrameTicks -> None
  ]
 ]

data /. {0 -> {0, 0, 0}, 1 -> {1, 1, 0}, 2 -> {1, 0.5, 0}};
myPlot[%, 2, 25, FrameTicks -> True]

enter image description here

share|improve this answer
add comment

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.