8
$\begingroup$

Bug introduced in 9.0 and fixed in 10.0.1


The simplest way to ask is to post the code of what I'm doing:

ListPlot[{Table[x, {x, 1, 10, 1}], Table[x + x^2, {x, 1, 10, 1}]}, 
  PlotMarkers -> None, PlotRange -> All, 
  PlotStyle -> {
   {Thickness[.005], Dashing[{.03, .015}], ColorData[1, 1]},   
   {Thickness[.0075], ColorData[1, 1]}},
  Joined -> True
]

When I did this in Mathematica 8, the first line was dashed and the second line was a thicker, solid line of the same color:

enter image description here

Now having upgraded to Mathematica 10 and the second line is also dashed, same as the first:

enter image description here

It seems that if I leave out an explicit Dashing[{x,x}] command, the curve inherits the last dashing style, rather than go back to the default! How do I get the second curve to be solid? More importantly, what has changed in Mathematica 10 that causes this?

Obviously, my real task is more complicated than this, but this will reproduce the behavior.

$\endgroup$
  • 1
    $\begingroup$ I confirm this problem (version 10 Wolfram Programming Cloud). Unless you explicitly use Dashing[{}] for a line, it inherits the Dashing spec from previous lines. It seems to happen only for the Dashing directive; other directives (Thickness, Color ...) seem to work fine. Btw, this happens with ListPlot (with the option Joined->True), not with ListLinePlot. $\endgroup$ – kglr Sep 3 '14 at 20:42
  • 3
    $\begingroup$ This is a bug, not a typo. $\endgroup$ – rcollyer Sep 3 '14 at 20:48
  • $\begingroup$ @rcollyer I wish you had tried harder to get my attention. Question reopened. $\endgroup$ – Mr.Wizard Sep 11 '14 at 11:37
6
$\begingroup$

Your code is missing a bracket and it should be a ListLinePlot. After correcting those errors I get one solid and one thinner dashed line just like you wanted.

ListLinePlot[{Table[x, {x, 1, 10, 1}], Table[x + x^2, {x, 1, 10, 1}]},
  PlotMarkers -> None, PlotRange -> All, 
  PlotStyle -> {{Thickness[.005], Dashing[{.03, .015}], 
    ColorData[1, 1]}, {Thickness[.0075], ColorData[1, 1]}}]

enter image description here

$\endgroup$
  • $\begingroup$ Thx Paw, this works for me. The missing bracket was just a typo. Any clue as to what is going on differently under the hood of v10 vs v8? I've run into a few issues like this where v10 seems to interpret my plotting commands differently v8. It's usually not a big deal, but this particular plot I needed the style to match previously published work. $\endgroup$ – Steve Sep 3 '14 at 20:22
  • $\begingroup$ Question edited to fix the typo. Should be correct now. Can anyone point me in the right direection as to what is going on v/v the difference between v8 and v10 that causes this? $\endgroup$ – Steve Sep 3 '14 at 20:46
  • $\begingroup$ @Steve I had fixed the typo, and improved the formatting. You got rid of my formatting. :P Also, there's a lot of changes under the hood. Looks like a bug slipped through. $\endgroup$ – rcollyer Sep 3 '14 at 20:59
  • $\begingroup$ @rcollyer Sorry, I'm new to this stackexchange thing! I upvoted your comment though. $\endgroup$ – Steve Sep 3 '14 at 21:10
4
$\begingroup$

This is fixed in 10.0.1. The output from ListPlot now matches that from ListLinePlot.


You are supposed to use ListLinePlot for line charts since Mathematica 6, which as paw 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.


The version 10.0.0 behavior has been confirmed as a bug.

  1. This is a bug, not a typo. – rcollyer (WRI employee)

  2. I reported the behavior of Dashed in ListPlot to WRI tech support, and in their reply they agreed it was a bug. Should the question, therefore, be tagged with the bugs tag? – m_goldberg

$\endgroup$
  • $\begingroup$ "The version 10.0.0 behavior has been confirmed as a bug." By whom ? Thanks for ignoring my answer. $\endgroup$ – eldo Sep 11 '14 at 23:07
  • $\begingroup$ @eldo Citations added. I did not ignore your answer; rather I feel that it does not properly address the question. $\endgroup$ – Mr.Wizard Sep 11 '14 at 23:13
  • $\begingroup$ OK - Sorry for the downvote. It was too temperamental :) $\endgroup$ – eldo Sep 11 '14 at 23:22
  • $\begingroup$ @eldo Perhaps I was at fault too. I was fixating on "More importantly, what has changed in Mathematica 10 that causes this?" but the OP did also ask "How do I get the second curve to be solid?" which you answered. +1 on yours as well. $\endgroup$ – Mr.Wizard Sep 11 '14 at 23:31
  • 1
    $\begingroup$ @eldo the bug, as Mr.W points out, is that the data are no longer isolated from one another, (cf. this answer). There's a partial isolation as each data set gets a default color, but allowing other directives to leak across data sets is just icky. $\endgroup$ – rcollyer Sep 12 '14 at 0:54
1
$\begingroup$

As per Documentation Dashing[{}] "specifies that lines should be solid". Hence

ListPlot[{Table[x, {x, 1, 10, 1}], Table[x + x^2, {x, 1, 10, 1}]},
 PlotMarkers -> None,
 PlotRange -> All,
 PlotStyle -> {
   {Dashing[{.03, .015}], Thickness[.005], ColorData[1, 1]},
   {Dashing[{}], Thickness[.0075], ColorData[1, 1]}},
 Joined -> True]

enter image description here

You have the same "problem" with V9.

Where are the bugs ? I just tried to remove this tag, but it stays.

$\endgroup$
  • $\begingroup$ Just because something was in v9, too, does not mean it should be there. $\endgroup$ – rcollyer Sep 11 '14 at 21:24
  • $\begingroup$ @rcollyer Continue to regard it as a "bug". For me it's logical. Kind of sorry that we disagree. – eldo just now edit $\endgroup$ – eldo Sep 11 '14 at 21:31

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.