This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / The Mathematica Book / Principles of Mathematica / The Structure of Graphics and Sound  /

2.9.17 Advanced Topic: Color Output

Specifications of color for different kinds of output devices.

When you generate graphics output in Mathematica, there are different specifications of color which are natural for different kinds of output devices. Sometimes output devices may automatically convert from one form of color specification to another. But Mathematica provides graphics directives which allow you directly to produce color specifications appropriate for particular devices.

Color directives in Mathematica.

Each color directive in Mathematica yields a definite color directive in the PostScript code that Mathematica sends to your output device. Thus, for example, the RGBColor directive in Mathematica yields setrgbcolor in PostScript. The final treatment of the PostScript color directives is determined by your output device, and the PostScript interpreter that is used.
Nevertheless, in most cases, the parameters specified in the Mathematica color directives will be used fairly directly to set the intensities or densities of the components of the color output.
When this is done, it is important to realize that a given set of parameters in a Mathematica color directive may yield different perceived colors on different output devices. For example, the actual intensities of red, green and blue components will often differ between different color displays even when the settings for these components are the same. Such differences also occur when the brightness or contrast of a particular color display is changed.
In addition, you should realize that the complete "gamut" of colors that you can produce by varying parameters on a particular output device is smaller, often substantially so, than the gamut of colors which can be perceived by the human visual system. Even though the space of colors that we can perceive can be described with three parameters, it is not possible to reach all parts of this space with mixtures of a fixed number of "primary colors".
Different choices of primary colors are typically made for different types of output devices. Color displays, which work with emitted or transmitted light, typically use red, green and blue primary colors. However, color printing, which works with reflected light, typically uses cyan, magenta, yellow and black as primary colors. When a color image is printed, four separate passes are typically made, each time laying down one of these primary colors.
Thus, while RGBColor and Hue are natural color specifications for color displays, CMYKColor is the natural specification for color printing.
By default, Mathematica takes whatever color specifications you give, and uses them directly. The option ColorOutput, however, allows you to make Mathematica always convert the color specifications you give to ones appropriate for a particular kind of output device.

Color output conversions.

One of the most complicated issues in color output is performing the "color separation" necessary to take a color specified using red, green and blue primaries, and render the color using cyan, magenta, yellow and black printing inks. Mathematica has a built-in algorithm for doing this conversion. The algorithm is based on an approximation to typical monitor colors and the standard set of four-color process printing inks. Note that the colors of these printing inks are not even close to complementary to typical monitor colors, and the actual transformation is quite nonlinear.
While Mathematica has built-in capabilities for various color conversions, you can also specify your own color conversions using ColorOutput->f. With this option setting, the function f is automatically applied to each color directive generated by Mathematica.
Note that while any of the color directives given above can be used in setting up graphics objects, simulated lighting calculations in Mathematica are always done using RGBColor, and so all color directives are automatically converted to this form when simulated lighting is used.

  • This defines a transformation on RGBColor objects, which extracts the red component, and squares it.
  • In[1]:= red[RGBColor[r_, g_, b_]] = GrayLevel[r^2]


  • This specifies that red should simply square any GrayLevel specification.
  • In[2]:= red[GrayLevel[g_]] = GrayLevel[g^2]


  • This plots the squared red component, rather than using the usual transformation from color to black and white.
  • In[3]:= Plot3D[Sin[x + y], {x, -3, 3}, {y, -3, 3},
    ColorOutput -> red]

    Note that if you give your own ColorOutput transformation, you must specify how the transformation acts on every color directive that arises in the image you are producing. For three-dimensional plots shaded with simulated lighting, you must typically specify the transformation at least for RGBColor and GrayLevel.