# Extracting Color Options from BarChart

I would like to extract the colors (i.e., obtain RGBColor[] or other full specification) of the different colors used in a bar chart such as this

BarChart[{{4, 4, 1, 0.05}, {3, 3, 1, 1}, {1, 1, 2, 2}, {2, 2, 4, 4}}]


for use in other figures, text and such. I've tried Options[BarChart] and AbsoluteOptions[...] and found only that the options are Automatic. I have also looked at a number of other posted problems focusing on extracting specific numerical Option values when the value is Automatic and none yield the answer. Likewise controlling colors in BarChart is straightforward and not the problem I'm addressing.

• Union@Cases[BarChart[....], _RGBColor, Infinity] is a first step ... Jan 11, 2016 at 16:58
• The default colors are ColorData[97]. Jan 15, 2016 at 14:43
• @rcollyer Thanks so much. How did you find out that the default colors are ColorData[97]? Jan 15, 2016 at 16:42
• @DavidG.Stork I work at wolfram. :) Jan 15, 2016 at 16:58
• @rcollyer OK, then... how do the rest of us find default values, such as colors? Jan 15, 2016 at 18:10

bar =
BarChart[{{4, 4, 1, 0.05}, {3, 3, 1, 1}, {1, 1, 2, 2}, {2, 2, 4, 4}}]


c = Cases[bar[[1]], _RGBColor, Infinity]


Union@c // InputForm


{RGBColor[0.4992, 0.5552, 0.8309304], RGBColor[0.7116405333333333, 0.4816, 0.5483194666666666], RGBColor[0.928, 0.5210666666666667, 0.2], RGBColor[0.982864, 0.7431472, 0.3262672]}

• Thanks very much. I think Mathematica should allow access to colors and other Automatic options directly, but your solution works perfectly. Jan 11, 2016 at 17:09
• Colors are not part of options but buried deep inside the graphic directives. I agree that there should be an easier way to identify the color scheme(s) used for a plot. Thanks for accept :)
– eldo
Jan 11, 2016 at 17:16
• A followup question: Is there a way to extract the color scheme under such circumstances? Jan 11, 2016 at 23:54

You can find the actual default style information using this:

ChartingResolvePlotTheme["Default", BarChart]

{{0.71, "DefaultChartBaseStyle" -> RGBColor[0.982864, 0.7431472, 0.3262672]}, {0.1,
GridLinesStyle -> Directive[
GrayLevel[0.5, 0.4]]}, {0.71,
"ChartDefaultStyle" -> (Blend[
Lighter[SystemPlotThemeDump$ThemeDefaultGradient, 0.2], #1] &)}, {0.1, "AxisPadding" -> Scaled[0.02]}, {0.1, "DomainPadding" -> Scaled[0.02]}, {0.1, "RangePadding" -> Scaled[0.05]}}  The key function: stylefn = (Blend[Lighter[SystemPlotThemeDump$ThemeDefaultGradient, 0.2], #1] &);


And four styles as used in the chart:

Array[stylefn, 4, {0, 1}]

{RGBColor[0.982864, 0.7431472, 0.3262672],
RGBColor[0.928, 0.5210666666666667, 0.2],
RGBColor[0.7116405333333333, 0.4816, 0.5483194666666666],
RGBColor[0.4992, 0.5552, 0.8309304]}
`

References: