Mathematica Notes – Coloring functions

Sometimes I wish life were always perfectly straightforward. As I said recently, I have figured out how to change the default sequence of colors for multiple graphs. I thought this would be a very short post… but there are a few additional things I need to cover in order to show that to you.

Since I usually use Mathematica® version 7, let me note that I am using version 8 for this work.

Let me start by showing you where we’re headed. If we make a list of the first five Legendre polynomials and ask Mathematica to plot them all, it chooses a set of five colors, one for each function:

You should now open the Color Schemes palette. At its most compact, it’s just

If your palette is at its most compact, click on the triangle for “Indexed”:

As you see from my screenshot, when I do that, the sequence of colors “1” is mildly highlighted… and it appears again at the bottom of the palette. Doesn’t that look just like the colors we got in our plot? Click on the leftmost blue color in the large selection at the bottom… I get the following:

Now ask for every fourth color starting with the first:

Those are the four blue colors in that sequence. They are slightly different. (Actually, on second take, it looks like there’s an extra color between the third and fourth dark blues. Too late now.)

The advantage of this set of colors is that I didn’t have to enumerate them… the disadvantage is that the sequence doesn’t have much variety. And the original purpose of this post was to show you how to change the default.

Let me remark that it took me a while to figure out that the default sequence was Indexed[1]… it took even longer to find out how to get the color specifications – that “ColorList” in the call to Colordata. (Thanks to the “Mathematica Navigator” book, when I finally remembered that I owned it.)

There’s one thing I have to show you before we proceed. That “Legacy@Linen” I used in the Plot command is only possible because I have loaded Dave Park’s Presentations package. Without it, the required command is


How did I get that answer? By opening the Named triangle on the Color Schemes palette, then choosing Legacy, then scrolling until I found Linen, and then clicking on “insert” after I found it. It helped a lot that I knew roughly where it was located in the list. (Or, easier, I could have sorted them by name.) I’ll show you that later. Anyway, that click on insert got me the


text. Here’s the relevant picture.

In the meantime, let me use the Mathematica syntax rather than my customary Presentations’ syntax. If we actually evaluate that ColorData command, we get the RGB values:

As I will say repeatedly, I like having the names. They’re easier to make sense of.

Alas, I have not figured out how to change both the colors and the thickness without a Table command. (If you know how, please enlighten me.) In particular, if I issue two PlotStyle directives, only the first is effective. That is, I can change the colors to a nicely varied set, using Indexed[6]:

But if I add another PlotStyle before the ColorData, to set the Thickness…

… I get the default colors. If I put the Thickness after the ColorData…

… it has no effect. Put them together in a list?

Two of the graphs are thick! And only two colors are used! Weird.

Braces around the Thickness? No change from the previous picture:

Put the thickness first?

Three of the graphs are thick… but we’re back to the default color sequence.

Don’t misunderstand: I can do this… I was just a little disappointed that it required a Table command… but we’ll need to use Table for colors other than Indexed, so I reckon I’ll get used to using it.

And I definitely like what I get:

You can see that I have set the PlotStyle so that it can handle up to 11 curves which is the number of colors in Indexed 6. Here, have a set of 12 functions:

Well… they all look thick, but I’m not sure I’d see a thin line even if there were one!

Using Presentations, by contrast, I could do the following, using AbsoluteThickness once to set the thickness of all the subsequent curves:

Having shown you that, let me restart, and use the ordinary Plot command, and the Mathematica specification


There are other colors we could have used… but the way to get to them is a little different. In particular, we’ve already seen that getting “Linen” does not use ColorList, as Indexed does.

Can we use a table for Legacy colors? First let’s see if Table works:

Those are coming out in named order. No, I wasn’t born knowing that. First Let’s look at the named order on the palette, entries 1-5:

And use my old trick of calling PieChart to see the colors in the table I built:

Those look like the same 5 colors to me.

And once we use a table for colors, we ought to include the Thickness. And given how light two of those colors are, let me change the background.

(Maybe I should have looked for an effective but less garish background.)

Will ColorList work? Yes, if we change [i] to [[i]]. But it delivers the very same list. That’s a shame, because adjacent colors – as opposed to adjacent names – are often quite different, too.

Let’s try Named… Crayola:

… with another change of background:

Let’s try another set of Named colors, GeologicAges – which apparently cannot be sorted by name! (Sort by color seems to be permanent.)

And which apparently requires ColorList and [[i]]… and which apparently has 70 colors. (The semi-colon suppresses a list of names, delivered after the error message. The point is that 70 works while 71 fails.)

Let’s get a selection of colors over the range available, stepping 15 at a time:

And use them:

What about Physical?

It appears that BlackBodySpectrum ranges from 1000 to 10,000, in contrast to the colors we’ve seen so far, which ranged over integer indices.

Note that the word “Physical” does not appear, nor does “ColorList”. Of course, “Physical” corresponds to “Indexed”, which also did not appear explicitly.

And Gradients? I recall something called SunsetColors… can I find them? Sure:

Note that these colors run from 0 to 1. Once again, choose a wide range, stepping by 0.2.

OK? I hope you’ve got a good idea of what we can do, and what the differences are (integer or continuum, ColorList or not).

We may often want to specify our own list of colors to be used for curves, but we could also just fall back on, say, Indexed[6]. As we have seen, once we specify a list of colors, we might as well include the Thickness directive.

Let me show you one final tool… which is another way to see what we have available.

The ColorData command with no parameters gives us the 4 categories we saw on the compact Color Schemes palette:

and that appears to show that the there are 1 + 69 = 70 different names. I had hoped that Range would work… and it does… with some help:

That was a digression, because we had had a question about the number of entries in GeologicAges. Returning to our investigation of ColorData, we could ask for, say, Named…

… and we see a list corresponding to the palette opened to Named.

We’ve already used ColorList… but “Panel” is extremely useful. Let’s try it on Legacy:

The crucial fact is that the Panel is live (in a notebook, not here on the blog): mouse over any disk and you see the name of the color in that disk. That’s why I knew where Linen occurred in the palette: in the panel, it’s third row almost dead center – so I knew it was at about the 25% point in the entire list.

If you click on a disk, unfortunately, you get the RGB rather than the name… and it’s the name that I find useful, so I type it in wherever I want it. That is, clicking on Linen gets us:


I encourage you to play around with ColorData. It complements the palette rather well.

In summary….

We can get information from both a Color Schemes palette, and from ColorData[] itself, especially the Panel keyword:

I have been using Background -> Legacy@Linen inside Mathematica graphics, but this form requires that Dave Park’s Presentations package be loaded. Without it, you and I must use


The default set of colors for displaying a list of curves is Indexed[1]:

The simplest change we could make is to, say, Indexed[6]:

If I want to alter the thickness, I usually use the Presentations package:

But without it, the only way I know is to use a Table command inside the PlotStyle:

And that’s it for now.


One Response to “Mathematica Notes – Coloring functions”

  1. David Cortes-Ortuño (@Aradan_d) Says:

    Thanks a lot! 🙂 Your post was very useful

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: