You are supposed to use ListLinePlot
for line charts since Mathematica 6, which as eldo illustrated handles this correctly.
The behavior of ListPlot
is due to the structure of the Graphics
object that is produced:
g1 = ListPlot[{Table[Sin[i], {i, 25}], Table[Cos[i], {i, 25}]}, Joined -> True,
PlotStyle -> {{Red, Thick, Dashed}, {Blue, Thin}}];
g1[[1]] /. (h : Hue | Line | Directive)[___] :> h[]
{{}, {Hue[], Directive[], Line[], Hue[], Directive[], Line[]}, {}}
Observe that the body is a single list of the form {color, directive, line, color, directive, line, ...}.
This has the implication that any earlier directive which is not expressly overridden by a later one will affect not only the Line
immediately following it but all the rest. Colors do not appear to persist in this fashion only because Mathematica automatically provides these styles.
Now compare the output of ListLinePlot
:
g2 = ListLinePlot[{Table[Sin[i], {i, 25}], Table[Cos[i], {i, 25}]},
PlotStyle -> {{Red, Thick, Dashed}, {Blue, Thin}}];
g2[[1]] /. (h : Hue | Line | Directive)[___] :> h[]
{{}, {{{}, {}, {Hue[], Directive[], Line[]}, {Hue[], Directive[], Line[]}}}, {}}
Note the structure {{color, directive, line}, {color, directive, line}, ...}. This has the effect of localizing the styling directives to a specific line; they will not persist across multiple lines.
I suppose either behavior could be intentional but I find the latter less surprising, and therefore better.