Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

I'm looking at Graphics Directives but can't figure out a way to turn off the Dashed graphics directive. For example, given

ListPlot[{Table[Sin[i], {i, 25}], Table[Cos[i], {i, 25}]}, 
 Joined -> True, PlotStyle -> {{Red, Thick, Dashed}, {Blue, Thin}}]

enter image description here

how do I restore a solid blue line? Thick can be "disabled" with Thin but what's Dashed's complement?

share|improve this question

marked as duplicate by Simon Woods, ybeltukov, Sjoerd C. de Vries, Michael E2, Mr.Wizard Sep 11 at 22:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
That's odd. I'm running 9.0.1.0 for Windows x64. –  Andrew Cheong Sep 5 at 23:22
    
Looks like a bug, but what happens if you invert Sin and Cos and the corresponding list of directives? –  Peltio Sep 5 at 23:28
    
@Peltio - If I switch the directive sets then the results are as expected—sequentially applied. (If you're saying it's one way to achieve my desired results, then I should clarify that this is only a simplified example.) –  Andrew Cheong Sep 5 at 23:31

4 Answers 4

up vote 15 down vote accepted

You can turn it off with Dashing[None].

ListPlot[{Table[Sin[i], {i, 25}], Table[Cos[i], {i, 25}]}, 
  Joined -> True, 
  PlotStyle -> {{Red, Thick, Dashed}, {Dashing[None], Blue, Thin}}]

plot

share|improve this answer
1  
@AndrewCheong "Dashing[{}] specifies that lines should be solid." from the docs of Dashing, and here is the example they give :) –  Öskå Sep 5 at 23:35
    
@Öskå - I missed that in the documentation. Thanks for pointing it out! –  Andrew Cheong Sep 5 at 23:36
    
@AndrewCheong So did I.. :) –  Öskå Sep 5 at 23:37
2  
It is my experience that wherever a graphic directive takes { } as an off switch, it will take None as well. –  m_goldberg Sep 5 at 23:38

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.

share|improve this answer
3  
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 Sep 9 at 1:11
    
@m_goldberg Based on that I believe it should so I added the tag. Thank you. –  Mr.Wizard Sep 9 at 3:31

Somehow easier for me than Mr. Goldberg's excellent answer:

ListLinePlot[{Table[Sin[i], {i, 25}], Table[Cos[i], {i, 25}]},
   PlotStyle -> {{Red, Thick, Dashed}, {Blue, Thin}}]

enter image description here

share|improve this answer
    
Unfortunately the comments on the question were deleted, but it appears that depending on the version of Mathematica (or perhaps not that, but some other state of the environment), omitting Dashed in subsequent sets of directives does not seem to disable the directive. Hence my asking. –  Andrew Cheong Sep 6 at 0:09
    
Oh, wait. I didn't see until @Mr.Wizard pointed out, that you're using ListLinePlot instead of ListPlot. –  Andrew Cheong Sep 6 at 0:17
1  
@Andrew You may have overlooked the difference between ListPlot and ListLinePlot. I expound on this in my own answer below. In my opinion eldo's answer is the correct solution, but m_goldberg's is the direct answer to the specific question you asked. –  Mr.Wizard Sep 6 at 0:18

Based on Mr.Wizard answer , I would suggest for this particular example is to switch the data and to put the dashed data at the end.

ListPlot[{Table[Cos[i], {i, 25}], Table[Sin[i], {i, 25}]}, 
 Joined -> True, PlotStyle -> {{Blue, Thin}, {Red, Thick, Dashed}}]

enter image description here

share|improve this answer

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