The following is a universal solution which extracts RGB color values assigned to the Line
primitives of a plot generated by built-in plotting functions of Mathematica 10:
Cases[fplot, {___, c_Directive, __Line} :>
ColorConvert[c, RGBColor], Infinity] // InputForm
{RGBColor[0.368417, 0.506779, 0.709798, 1.], RGBColor[0.880722, 0.611041, 0.142051, 1.],
RGBColor[0.560181, 0.691569, 0.194885, 1.], RGBColor[0.922526, 0.385626, 0.209179, 1.]}
The above pattern is found by inspection of internal structure of Graphics
objects produced by such functions as Plot
, ListLinePlot
, ParametricPlot
, ContourPlot
etc. of Mathematica 10.4.1. It is tested with plots generated by all listed functions and works quite reliably. If you encounter a case when it fails, please let me know.
For previous Mathematica versions more involved approach based on the colorQ
function of Mr.Wizard is necessary. For example, for version 8.0.4 the following should be sufficiently general (but in many situations it will lose Opacity
specification):
colorQ = Quiet@Check[Blend@{#, Red}; True, False] &;
Cases[fplot, {Longest[___], c_?colorQ, ___, __Line} :> ColorConvert[
If[Head[c] =!= Directive, c, Last@Cases[c, _?colorQ, Infinity]]
, RGBColor], Infinity]
{RGBColor[0.2472, 0.24, 0.6], RGBColor[0.6, 0.24, 0.442893],
RGBColor[0.6, 0.547014, 0.24], RGBColor[0.24, 0.6, 0.33692]}
This solution should work the same way with versions 9 and 10. The problem with Opacity
is difficult to avoid because in version 8 ColorConvert
cannot work with Directive
.
For inspection of the structure of Graphics
I recommend my shortInputForm function:
An advanced description of the Mathematica graphical programming language can be found in these threads:
If you wish to find the default colors used by the built-in plotting functions, you should consult with the following threads:
Plot
function the colors are given byColorData[97, "ColorList"]
$\endgroup$