9
$\begingroup$

The top one is fine, but if I change Red into dashed version, it behaves erratically.

enter image description here

$\endgroup$
4
  • $\begingroup$ Use Directive[Blue,Dashed] instead of {Blue, Dashed}. $\endgroup$
    – Szabolcs
    Commented Feb 20, 2016 at 0:36
  • $\begingroup$ Problem solved. Thank you so much! It seems that only changing one of it in your way is sufficient. $\endgroup$
    – Wendy
    Commented Feb 20, 2016 at 0:40
  • 2
    $\begingroup$ Since version 6, Directive should always be used instead of {...} when specifying a list of styles... (like in legends, PlotStyle, etc.) Lists are ambiguous and cause problems. $\endgroup$
    – Szabolcs
    Commented Feb 20, 2016 at 0:43
  • $\begingroup$ Thank you again for your helpful comments. $\endgroup$
    – Wendy
    Commented Feb 20, 2016 at 1:29

1 Answer 1

6
$\begingroup$

I think the behavior of LineLegend exhibited in the question, if not a bug, is within an epsilon of a bug. Consider that the following all succeed ...

LineLegend[{{Red, Dashed}, Green, Blue}, {"r", "g", "b"}]

LineLegend[{{Red, Dashed}, {Green, Dashed}, Blue}, {"r", "g", "b"}] 

LineLegend[{Directive[Red, Dashed], {Green, Dashed}, {Blue, Dashed}}, {"r", "g", "b"}]

LineLegend[{{Red, Dashed}, Directive[Green, Dashed], {Blue, Dashed}}, {"r", "g", "b"}]

LineLegend[{{Red, Dashed}, {Green, Dashed}, Directive[Blue, Dashed]}, {"r", "g", "b"}]

... and that this is the only failure case.

LineLegend[{{Red, Dashed}, {Green, Dashed}, {Blue, Dashed}}, {"r", "g", "b"}]

The singleton nature of the failure strikes me as indicating there is some edge case that has been missed in the Mathematica code underlying the evaluation or internal use of the 1st argument of LineLegend.

$\endgroup$
2
  • 1
    $\begingroup$ It's an "internal" use to make it compatible with ChartLegends, see the output of BarChart with multiple data sets. $\endgroup$
    – rcollyer
    Commented Aug 9, 2016 at 13:03
  • $\begingroup$ If not a bug, definitely a WTF $\endgroup$
    – Chris K
    Commented Mar 7, 2022 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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