22

(Note: All the answers to this question are valid for versions of Mathematica before version 10. For versions 10 and above, see https://mathematica.stackexchange.com/questions/54486/how-to-access-new-colour-schemes-in-version-10 and https://mathematica.stackexchange.com/questions/54629/what-are-the-standard-colors-for-plots-in-mathematica-10.)

When using the Plot or ListPlot command in Mathematica, certain default colors are chosen.

For reasons of uniformity within some report I would like to use them along with the PlotStyle option. It turned out that I cannot reproduce the default colors with the pre-defined color names, although blue and purple seem to be somehow close.

Hence my question:

How can I chose the standard colors used by Mathematica in plots along with PlotStyle?

Thank you in advance.

Nice answers were given by belisarius and Sjoerd from which we can conclude that

Plot[Sin[x], {x, 0, 2 Pi}, PlotStyle -> ColorData[1, 4]]

will result in a sine plotted in the fourth standard color, some nice green.

tparker
  • 689
  • 1
  • 6
  • 17
Robert Filter
  • 1,661
  • 3
  • 12
  • 14

3 Answers3

20

I know this is really late to the game, but the expression used to generate the nth color in ColorData[1] is:

Hue[FractionalPart[0.67 + 2.0 (i - 1)/GoldenRatio], 0.6, 0.6]

Update Based on Alexey's comment below, you can find this using:

ColorData[1] // InputForm
Eli Lansey
  • 1,130
  • 2
  • 15
  • 28
17

The colors used by Plot are in ColorData[1].

Compare

Graphics[MapIndexed[{#1, 
    Tooltip[Rectangle[{#2[[1]], 0}, {#2[[1]] + 1, 1}], #1]} &, 
  ColorData[1] /@ Range[40]]]

enter image description here

with Belisarius' colors

Graphics[MapIndexed[{#1, 
    Tooltip[Rectangle[{#2[[1]], 0}, {#2[[1]] + 1, 1}], #1]} &, 
  Cases[ListPlot[Table[{i}, {i, 40}]], Hue[x__], Infinity]]]

enter image description here

They are the same, except one is terms of Hue and the other in terms or RGBColor

Community
  • 1
  • 1
Sjoerd C. de Vries
  • 16,122
  • 3
  • 42
  • 94
  • 6
    I'm afraid this is not true for Mathematic 10 anymore. With the introduction of PlotThemes a lot changed. The default plot scheme accessible by `ColorData` is `ColorData[97, x]` as pointed out in this thread: http://mathematica.stackexchange.com/questions/54629/what-are-the-standard-colors-for-plots-in-mathematica-10 – Thomas Fankhauser Sep 04 '14 at 09:36
12

If you do:

ListPlot[Table[{i}, {i, 10}]] // FullForm  

You get the first 10 Hues used.

Or this gives you a ready to use list:

hues = Cases[ListPlot[Table[{i}, {i, 10}]], Hue[x__], Infinity]

{Hue[0.67, 0.6, 0.6],     Hue[0.906068, 0.6, 0.6], 
 Hue[0.142136, 0.6, 0.6], Hue[0.378204, 0.6, 0.6], 
 Hue[0.614272, 0.6, 0.6], Hue[0.85034, 0.6, 0.6], 
 Hue[0.0864079, 0.6, 0.6],Hue[0.322476, 0.6, 0.6], 
 Hue[0.558544, 0.6, 0.6], Hue[0.794612, 0.6, 0.6]}  

Usage sample:

SphericalPlot3D[\[Phi], {\[Theta], 0, Pi}, {\[Phi], 0, 3 Pi},
 Epilog -> 
  Table[Inset[Framed[Style["Spiral", 20],
        Background -> hues[[i]]],
             {i/15 + .1, i/15}], 
  {i, 10}]]  

enter image description here

If you prefer the RGB color space you may do:

rgbs= ColorConvert[#, "RGB"] & /@ hues

**Edit ** Comparing with Eli's formula:

mine = Cases[ListPlot[Table[{i}, {i, 10}]], Hue[x__], Infinity]
elis = Table[Hue[FractionalPart[0.67 + 2.0 (i-1)/GoldenRatio],0.6,0.6], {i,1,10}]
Chop[(mine- elis) /. Hue[x_, __] -> x]
(* -> {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} *)

Great, Eli!

Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190