8
$\begingroup$

My code is a simple function which I plot for two different times t

up[x_, t_] := un*Exp[I*((kr + I*ki)*x - (wr + I*wi)*t)];

un = 1;
kr = 2*Pi;
ki = 0.1;
wr = 0.1;
wi = 0.1;

a0 = Show[
  Plot[Re[up[x, 1]], {x, 0, 10}, PlotRange -> All, 
   AxesLabel -> {Style["x", FontSize -> 13], 
     Style["q'", FontSize -> 13]}, 
   PlotLegends -> 
    PointLegend[{Blue}, {"\!\(\*SubscriptBox[\(t\), \(0\)]\)"}]], 
  Plot[Re[up[x, 5]], {x, 0, 10}, PlotRange -> All, 
   AxesLabel -> {Style["x", FontSize -> 13], 
     Style["q'", FontSize -> 13]}, PlotStyle -> Orange, 
   PlotLegends -> 
    PointLegend[{Orange}, {"\!\(\*SubscriptBox[\(t\), \
\(1\)]\)>\!\(\*SubscriptBox[\(t\), \(0\)]\)"}]]]

enter image description here

How to set the same blue tone from Plot (default) to the legend label?

$\endgroup$
3
  • 8
    $\begingroup$ ColorData[97][1] at least in version 11 $\endgroup$ Mar 14, 2018 at 19:12
  • $\begingroup$ Here's an answer with this and more: mathematica.stackexchange.com/a/54632/38205 $\endgroup$
    – b3m2a1
    Mar 14, 2018 at 19:44
  • $\begingroup$ You can see all the colors used, including axes, with InputForm@DeleteDuplicates@Cases[plot, _?ColorQ, Infinity]. $\endgroup$
    – Michael E2
    Mar 14, 2018 at 19:58

2 Answers 2

5
$\begingroup$
Plot[{Re[up[x, 1]],Re[up[x, 5]] }, {x, 0, 10}, PlotRange -> All, 
   AxesLabel -> {Style["x", FontSize -> 13],  Style["q'", FontSize -> 13]}, 
   PlotLegends -> PointLegend[Automatic,{Subscript[t,0]  ,Subscript[t,1]>Subscript[t,0]}]]

enter image description here

Using ColorData[97,"ColorList"][[;;2]] in place of Automatic gives the same result.

$\endgroup$
3
$\begingroup$

If you do not specify a color, the legend will get it from the plot:

a0 = Show[
  Plot[Re[up[x, 1]], {x, 0, 10}, PlotRange -> All, 
   AxesLabel -> {Style["x", FontSize -> 13], 
     Style["q'", FontSize -> 13]},
   PlotLegends -> PointLegend[{"\!\(\*SubscriptBox[\(t\), \(0\)]\)"}]],
  Plot[Re[up[x, 5]], {x, 0, 10}, PlotRange -> All, 
   AxesLabel -> {Style["x", FontSize -> 13], 
     Style["q'", FontSize -> 13]}, PlotStyle -> Orange,
   PlotLegends -> 
    PointLegend[{"\!\(\*SubscriptBox[\(t\), \(1\)]\)>\!\(\*SubscriptBox[\(t\), \(0\)]\)"}]]]

Mathematica graphics

$\endgroup$

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