23

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
dearN
  • 5,341
  • 3
  • 35
  • 74

2 Answers2

31

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:

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
rm -rf
  • 88,781
  • 21
  • 293
  • 472
  • 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 – rm -rf May 20 '12 at 18:29
  • 1
    Apart from GrayLevel[], there's also ColorData["GrayTones"]. – J. M.'s missing motivation Jun 16 '12 at 10:43
4

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]

Mathematica graphics

For discrete plots:

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

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

Mathematica graphics

tkott
  • 4,939
  • 25
  • 44