54
$\begingroup$

Many colour schemes and colour functions can be accessed using ColorData.

Version 10 introduced new default colour schemes, and a new customization option using PlotTheme. The colour themes accessible with PlotTheme have both discrete colour schemes and gradients.

Is there a standard way to access these? I.e. get a colour function that take a real argument in $[0,1]$ and returns a shade, or one that takes an integer argument and returns a colour, as with ColorData.

$\endgroup$
6
  • 5
    $\begingroup$ That's a good question. I know the new default colors are ColorData[97] with some slight variations between different plots. $\endgroup$
    – rcollyer
    Jul 10, 2014 at 19:15
  • $\begingroup$ The first two colours are occasionally exchanged, e.g. in Histogram. $\endgroup$
    – Szabolcs
    Jul 10, 2014 at 19:17
  • $\begingroup$ Right, and sometimes lightened/darkened depending on the general needs of the plot type. $\endgroup$
    – rcollyer
    Jul 10, 2014 at 19:19
  • $\begingroup$ I notice that you haven't Accepted kguler's answer. I added my own including a mapping for ColorData indexed colors and information on how to find the gradient used by e.g. BarChart[{Range@99}, PlotTheme -> "Sunrise"]. Is this more to your liking? Is there something else I can look for to improve my answer? $\endgroup$
    – Mr.Wizard
    Aug 4, 2014 at 21:34
  • $\begingroup$ @Mr.Wizard I forgot to accept! $\endgroup$
    – Szabolcs
    Aug 4, 2014 at 21:35

2 Answers 2

47
$\begingroup$

Update 2: The content and organization of $PlotThemes in versions 10 and 9 are very different. In Version 10

 Charting`$PlotThemes

gives

enter image description here

whereas in Version 9, the content is organized around Charting/Plotting functions (See the picture in original post below.)

The color schemes can be obtained using:

 "Color"/. Charting`$PlotThemes
 (* BackgroundColor, BlackBackground, BoldColor, ClassicColor, CoolColor,
    DarkColor,GrayColor, NeonColor,PastelColor, RoyalColor, VibrantColor, WarmColor, 
    DefaultColor, EarthColor, GarnetColor, OpalColor, SapphireColor, SteelColor,
    SunriseColor, TextbookColor, WaterColor} *)

 Grid[{#,Row@(("DefaultPlotStyle"/.(Method/. 
   Charting`ResolvePlotTheme[#,   ListPlot]))/.
      Directive[x_,__]:>x)}&/@("Color"/. Charting`$PlotThemes),Dividers->All]

enter image description here

Update: The function that defines the color schemes and styles seems to be ResolvePlotTheme, which is in the Charting context in both Version 9 and 10.

?Charting`ResolvePlotTheme
(* too long  to copy here ... *)

For example,

Charting`ResolvePlotTheme["Vibrant", ContourPlot]
(* {BaseStyle -> GrayLevel[0.5], BoundaryStyle -> None, 
   ColorFunction -> (Blend[{Hue[0.5, 1, 0.5], Hue[0.35, 0.5, 0.7], 
                     Hue[0.17, 0.7, 0.9]}, #1] &), ContourStyle -> GrayLevel[1, 0.5],
   GridLines -> Automatic, 
   GridLinesStyle -> Directive[GrayLevel[0.5], Dashing[{0, Small}]], 
   Method -> {"GridLinesInFront" -> True}}  *)

So, one can access the color functions used in these themes using something like;

 Grid[{#, ColorFunction /. Charting`ResolvePlotTheme[#, ContourPlot]} & /@
          ("ContourPlot" /. Charting`$PlotThemes), Dividers -> All]

enter image description here

More generally, one can get the settings for ColorFunction, ChartStyle, PlotStyle BaseStyle etc. using a similar approach:

Grid[{#, Column@FilterRules[Charting`ResolvePlotTheme[#, PieChart], 
         {ColorFunction, ChartStyle, BaseStyle}]} & /@
  ("PieChart" /. Charting`$PlotThemes), Dividers -> All] 

enter image description here


PlotTheme seems to work in Version 9.0.1.0 as an undocumented feature:

?*`*PlotTheme*

enter image description here

After Unprotect and ClearAttributes[--,ReadProtected] one can access some details. For example:

?Charting`$PlotThemes

enter image description here

And, despite syntax hightlighting suggesting error, they work as expected:

Row[Plot[Table[BesselJ[n, x], {n, 5}], {x, 0, 10}, Evaluated -> True, 
ImageSize -> 400, PlotLabel -> Style[#, 20], 
Charting`PlotTheme -> #] & /@ {"Vibrant", "Monochrome"}]

enter image description here

$\endgroup$
20
$\begingroup$

For ease of direct access I have found through digging the following relationships for indexed colors:

map = {"Default" -> 97, "Earth" -> 98, "Garnet" -> 99, "Opal" -> 100, "Sapphire" -> 101, 
   "Steel" -> 102, "Sunrise" -> 103, "Textbook" -> 104, "Water" -> 105, 
   "BoldColor" -> 106, "CoolColor" -> 107, "DarkColor" -> 108, "MarketingColor" -> 109, 
   "NeonColor" -> 109, "PastelColor" -> 110, "RoyalColor" -> 111, "VibrantColor" -> 112, 
   "WarmColor" -> 113};

For example:

ColorData["Sunrise" /. map, "ColorList"]

enter image description here

Visually:

enter image description here

("Default" was added manually; it is not listed with the others that I can find.)

In addition to indexed colors each of these PlotThemes has rules for gradient colors, Financial plots, Wavelet plots etc. For example "MarketingColor" and "NeonColor" use the same indexed color scheme but other details are different.

This additional data may be conveniently found as follows. (You will need step.)

Plot[x, {x, 0, 1}]; (* preload PlotThemes system *)

System`PlotThemeDump`resolvePlotTheme["BoldColor", ""] // step

System`PlotThemeDump`resolvePlotTheme["Sunrise", ""]   // step

enter image description here

You can copy values directly or let the Switch statement assign the value to the appropriate Symbol.
For example to find the gradient colors used by:

BarChart[{Range@98}, PlotTheme -> "DarkColor"]

enter image description here

We can use this:

System`PlotThemeDump`resolvePlotTheme["DarkColor", ""];

System`PlotThemeDump`$ThemeColorGradient

enter image description here

You can of course view all definitions at once but be warned that it is long:

?? System`PlotThemeDump`resolvePlotTheme

This Symbol can also used to customize plot themes as I described in the second half of my answer to:

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.