Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

The help for the Export function is absolutely unclear. How can I specify options for my output format?

According to the documentation, PNG supports grayscale output. But this doesn't work, I still get an RGB image.

Export["somefile.png", something, "ColorSpace" -> "Grayscale"]
share|improve this question
I think ColorSpace works only with Import, not with Export. Perhaps, you can ColorConvert[something,"Grayscale"] and then export as a workaround? – kglr Nov 20 '12 at 15:40
Related: – Mr.Wizard Nov 21 '12 at 0:19

2 Answers 2

The following solution works as a formatting step prior to performing the export of your output

(Please note that this is not my solution! it was posted here by @rm -rf - i'm reposting it because it got a little lost in the comments/editing of the other question and it seems to be a very effective post-processing method).

Where other approaches do not work, this one seems to get over the line.

toGrayScale[y_] := y /. x__?
(MemberQ[{RGBColor, Hue, CMYKColor}, Head[#]] &) :> ColorConvert[x, "Grayscale"]

greyscalemyPlot = myPlot // toGrayScale

Export["greyscale-myplot.eps", greyscalemyPlot]

I found this particularly useful when I have an array of plots like a GraphicsGrid of ListPlots or where I have used Show to overlay two plots. in both cases it is a pain to go back in and modify the options using GreyLevel etc.

share|improve this answer
@rm -rf, yes, that is what I meant, thanks. Happy to remove this answer if you want to post similar or simply redirect back to the original answer. As I said I have found it to be a very handy post-processing approach. Cheers. – geordie Nov 20 '12 at 23:48
Alternatively: toGrayScale[y_] := y /. x : (_RGBColor | _Hue | _CMYKColor) :> ColorConvert[x, GrayLevel] – J. M. Nov 20 '12 at 23:48
@Grrwebb No worries, you don't have to delete this at all; I'm glad that you found it useful :) – R. M. Nov 21 '12 at 3:50

The documentation can be a bit confusing sometimes, but in this case it is clearly stated in the elements section of the png help-page

enter image description here

The option "ColorSpace" is only for Import.

Anyway, what happens when you Export a png-file is, that (when it is a Graphics or Graphics3D) Mathematica calls Rasterize which accepts the ColorSpace option. Therefore one solution to your problem is to use

Export["tmp/gray.png", Rasterize[p, ColorSpace -> "Grayscale"]]

A quick test shows, that it creates identical images which only differ in ColorSpace

p = Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}];
Export["tmp/color.png", p]
Export["tmp/gray.png", Rasterize[p, ColorSpace -> "Grayscale"]]

   Import[img, #] & /@ {"BitDepth", "ColorSpace", "DataType", 
     "ImageSize"}] /@ {col, gray} // Column

and they fit exactly onto another

ImageMultiply @@ (Import /@ {col, gray})

Mathematica graphics

share|improve this answer

Your Answer


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.