I want to make a Plot with a styled line, as follows:

testFunc = E^((x - 2)^(3/2)/(2*Sqrt[2])); 
Plot[Style[testFunc, Darker[Red], Dashed], {x, 1, 10}, 
  PlotLegends -> {StringForm["f(x) = ``", testFunc]}]

The PlotLegends entry comes out the wrong colour - it accepts the dashed line, but not that it's red:

enter image description here

How do I fix this?

  • $\begingroup$ Reported the bug. $\endgroup$ – rcollyer Sep 24 '19 at 1:43
  • $\begingroup$ Rather than use Style around the function, use the PlotStyle option: Plot[testFunc, {x, 1, 10}, PlotStyle -> Directive[Darker[Red], Dashed], PlotLegends -> Placed[{testFunc}, {0.5, 0.5}]] $\endgroup$ – Bob Hanlon Sep 24 '19 at 4:59

It looks like Plot does not take all the styles applied via Style into account. Since it does work in principle (the dashing is applied), you can simply combine the styling directives into one using Directive. This produces the expected result:

testFunc = E^((x - 2)^(3/2)/(2*Sqrt[2]));
 Style[testFunc, Directive[Darker[Red], Dashed]],
 {x, 1, 10},
 PlotLegends -> {StringForm["f(x) = ``", testFunc]}

enter image description here

| improve this answer | |
  • $\begingroup$ Also, simply wrapping them in a list works fine for this case. $\endgroup$ – rcollyer Sep 24 '19 at 1:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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