Match colors to plot themes

Use

colors=(("DefaultPlotStyle"/.(Method /. 
     Charting`ResolvePlotTheme["Scientific" ,  ListLinePlot]))/. Directive[x_,__]:>x)

to get the colors used in the "Scientific" plot theme. Then use colors as the first argument of LineLegend:

Column[{
 Row[{Style["Data from experiment 5B", FontFamily -> "Times", 
 FontSize -> 12]}, Alignment -> Center, 
 ImageSize -> (4 + 4 + 0.5) 72],
 Row[{ListLinePlot[data1, opts], Spacer[0.5 72], 
 ListLinePlot[data2, opts]}],
 Row[{ListLinePlot[data3, opts], Spacer[0.5 72], 
ListLinePlot[data4, opts]}],
 Row[{LineLegend[colors, {"x-direction", "y-direction ", 
  "z-direction"}, LegendLayout -> "Row", 
 LabelStyle -> {FontFamily -> "Times", FontSize -> 12}]}, 
  Alignment -> Center, ImageSize -> (4 + 4 + 0.5) 72]
  }]

enter image description here


This is not another answer but rather an extension of kguler's correct response. Further issues are also identified. In order to help use kguler's answer I have made a function which may be useful to others.

ClearAll[plotColors];
plotColors::usage = 
 "plotColors[plotType,plotTheme] gives a list of the colors used in \
a plot when several curves are drawn. Here plotType is, for example, \
Plot or ListLogPlot while plotTheme may be \"Scientific\", \
\"Classic\" etc.";

plotColors[plotType_, plotTheme_] := 
 ("DefaultPlotStyle" /. (Method /. 
   Charting`ResolvePlotTheme[plotTheme, plotType])) /. Directive[x_, __] :> x

This function gives a nice list of colors when implemented, for example

plotColors[Plot, "Scientific"]
plotColors[ListLogPlot, "Scientific"]
plotColors[ListLinePlot, "Classic"]

Giving

*Mathematica* graphics

Another nice feature is that all the colors are listed but there is no need to reduce the number to that needed. This is done automatically.

For some plots my function does not work. For example for ParametricPlot there is both a DefaultBoundaryStyle and a DefaultPlotStyle covering the cases where a parametric region is plotted as an alternative to a curve. This may be discovered by typing

Charting`ResolvePlotTheme["Scientific", ParametricPlot]

Which gives

Mathematica graphics

Clearly Charting`ResolvePlotTheme is a function that needs to be explored.


I propose using the lower-level System`PlotThemeDump`resolvePlotTheme to find the information you need. This reveals the color scheme number itself rather than resolving to a list of Directives.

You must give the plot function name as a String. The key you are looking for is "DefaultColor":

Themes`ThemeRules;  (* preload PlotThemes subsystem *)

"DefaultColor" /. 
   Last /@ System`PlotThemeDump`resolvePlotTheme["Scientific", "ListLinePlot"]
108

That is all you need in your LineLegend to get the color scheme you want:

LineLegend[108, {"x-direction", "y-direction ", "z-direction"},
 LegendLayout -> "Row", LabelStyle -> {FontFamily -> "Times", FontSize -> 12}]

enter image description here