Mathematica‘s True Colors
June 22, 2007 — Yu-Sung Chang, Technical Communication & Strategy
We can’t emphasize enough how important colors are in scientific visualization. Colors can convey the information which cannot be represented by geometry only. Sometimes, the data is just unreadable without proper colors in place. Most of all, colors can make graphics and plots more attractive and appealing.
In previous versions of Mathematica, it was not always easy to pick the right colors or color functions. Probably, you would end up playing with the values of RGBColor or Hue, which can be both tedious and time consuming.
During the development of Mathematica 6, we committed to change this situation. First off, we made–among dozens of newly added controls–a few specifically dedicated to color input.
Let’s start with the simplest one, ColorSetter:
If you click this naive-looking square in Mathematica, the system color dialog box is brought up and you can interactively choose colors.
For more fun, you can use the setter with the new Dynamic function:
Change the value of “c” in the color dialog box and the color of the disk changes dynamically along with it.
Of course, if you do not wish to use the dialog box, and want to make a self-contained control within a notebook, you can use ColorSlider instead:
So, the interactive controls are nice and all, but how about programmatic ways to work with color? In Mathematica 6, we’ve extended the color-related functions in several different ways.
If you feel adventurous, try this:
For each point on the plot, we pick a color from the image, which, in return, produces a texture-like effect. Texturing a surface is not what VertexColors is originally intended for, but still you can simulate the effect.
Last but not least, there is ColorData. It seemed to us that many people want to use names for their colors. On the other hand, we also found that those names are quite arbitrary, and differ from one context to the other. So, instead of adding a bunch of new color names at will, we organized popular named colors and grouped them together. And what is the best way to present them? Using built-in computable data sources, of course.
Here is an example. If you want to specify the color “DeepSkyBlue”, defined in the HTML standard color names, you can use:
Or, ColorData["HTML","DeepSkyBlue"] can be used instead. In addition, you can choose the RGB values of the colors interactively (complete with Tooltips):
Of course, we didn’t forget our beloved named colors, such as Gold or Banana, which were part of the Graphics`Colors package in previous versions. Now, they can be accessed immediately using ColorData["Legacy"]["Gold"], for instance.
You will be happy to know that there are even colors like ColorData["GeologicAges"]["Jurassic"]–useful if you’re a geologist. The list of these named color schemes can be acquired by entering ColorData["Named"].
When ColorData was first conceived during development, we were somewhat worried of colors being presented through curated data. But it turned out that it wasn’t a bad idea at all. In addition to named color schemes, we were able to introduce a great number of different sets of colors. Here is one example:
You will notice that there is an unusual color function called “Pastel“. This is a shortcut for ColorData["Pastel"]. It returns a gradient function, defined over a unit interval.
This gradient is part of a big collection called ColorData["Gradients"]. The next example generates a list of thumbnails of all the gradients:
In addition to “Named” and “Gradients“, ColorData contains other collections, too. One of the easiest ways to access everything in ColorData is to use the new Color Schemes palette, under the Palettes menu:
There are so many things that you can achieve with the new color-related functions. I’ll end here by showing a few neat examples from our new Documentation Center as well as from The Wolfram Demonstrations Project site.
You’ll find that discovering your own true colors is easier than ever with Mathematica 6.