# How to save plots in grayscale

As sophomoric as this question seems, how should I save plots in grayscale in Mathematica?

I generally like eps images for their scalability and I use ghostscript or other third party perl scripts to convert my images to grayscale.

-

One way would be to use ColorConvert to convert the RGB or Hue values to gray scale. Here's an example:

Plot[{Sin[x], Cos[x], Exp[-x^2], Sinc[π x]}, {x, 0, π}] /.
x : _RGBColor | _Hue | _CMYKColor :> ColorConvert[x, "Grayscale"]


For 2D plots that accept a ColorFunction, you can simply use GrayLevel to get the plot in grayscale as:

DensityPlot[
Sin[x ^2 + y^2], {x, 0, 3}, {y, 0, 3},
ColorFunction -> GrayLevel,
PlotPoints -> 100
]


Typically, these grayscale plots are useful when submitting to journals that charge exorbitant prices just to print in colour. However, just a note of caution that discerning different shades of gray is not easy. For the most effect, it is recommended (at least in the journals I publish in), that you also change the line type for your different curves (and not more than 4 curves/plot). You should also choose the colours (or colourscale, for 2D surface plots) wisely so that they convert well to grayscale. For example:

-
Ahh, I was trying to figure out how to use ColorConvert without changing the entire plot to an Image, which then loses it's vector goodness. – tkott Mar 20 '12 at 14:16
I got this somewhere (may be on Mathematica.SE?) toGrayScale[y_] := y /. x__?(MemberQ[{RGBColor, Hue, CMYKColor}, Head[#]] &) :> ColorConvert[x, "Grayscale"] so that it can be done as an afterthought. e.g. ListLinePlot[RandomReal[{0, 1}, {3, 15, 2}]] // toGrayScale; it works also on ContourPlot etc... (not very different from the solution above though !) – chris May 20 '12 at 16:12
@chris You probably got that from this answer :) See the edit history... Mr.Wizard simply rephrased that more concisely – R. M. May 20 '12 at 18:29
Apart from GrayLevel[], there's also ColorData["GrayTones"]. – J. M. Jun 16 '12 at 10:43

One way would be to roll your own color functions. For continuous use:

grayScale = Blend[{Black, White}, #1] &

ContourPlot[Sin[x + y], {x, 0, 2 \[Pi]}, {y, 0, \[Pi]},
ColorFunction -> grayScale]


For discrete plots:

grayColorList = (Blend[{Black, White}, #] & /@ Range[0, 1, 0.1])

Plot[Sin[x], {x, 0, 2 \[Pi]}, PlotStyle -> grayColorList[[1]]]


-
In what way does your grayScale function differ from the built-in GrayLevel? – celtschk Mar 21 '12 at 16:21
It doesn't, I just didn't remember about GrayLevel :) – tkott Mar 21 '12 at 16:40