7
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ Reported the bug. $\endgroup$ – rcollyer Sep 24 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 at 4:59
6
$\begingroup$

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]));
Plot[
 Style[testFunc, Directive[Darker[Red], Dashed]],
 {x, 1, 10},
 PlotLegends -> {StringForm["f(x) = ``", testFunc]}
 ]

enter image description here

$\endgroup$
  • $\begingroup$ Also, simply wrapping them in a list works fine for this case. $\endgroup$ – rcollyer Sep 24 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.