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.

I have noticed cases where Line produces dots in a graphics object when I think it shouldn't. The first of these is:

Line[{{0., 0.}}]

The second is:

Line[{{0., 0.}, {0., 0.}}]

Longer lists of same point do not produce dots. To see this evaluate

repeatPts [pt_, n_] := Line[ConstantArray[pt, n]]
Graphics[{Thickness[.125], repeatPts[{0., 0.}, #], repeatPts[{1., 1.}, #]},
  ImageSize -> 50, Frame -> True, FrameTicks -> None, PlotRangePadding -> .3] & /@ Range[5]

Dots.png

Is this version or platform depended? I got the results shown above on with V9.0.1 running on OS X. Should it be considered a bug or a weird feature?

share|improve this question
1  
9.0.1, Linux: another behavior –  ybeltukov Dec 7 '13 at 23:50
    
8.0.4 Linux, same as above. (Including square-looking dots in the last three) –  ssch Dec 7 '13 at 23:51
1  
9.0.1 OS X, slightly different: dropbox.com/s/42kwqfdu3cv4vh5/… –  Szabolcs Dec 8 '13 at 0:14
1  
With Line[..., VertexColors -> {Red, Blue}] the result is quite surprising. –  ybeltukov Dec 8 '13 at 0:15
1  
If it helps, Exporting to eps we see in the anomolous cases it is actually drawing a little circle (8 bezier arcs in fact -- some 12 lines of code to make a dot!). A default Point[] on the other hand is rendered as a zero length line with a round endcap. –  george2079 Dec 9 '13 at 15:02
show 3 more comments

4 Answers

up vote 3 down vote accepted

Inspired by george2079's answer:

line[arg__] := Line[arg];
line[{x_ ..}, ___] := {};
share|improve this answer
    
Way faster than mine if you have lots of points. –  george2079 Dec 9 '13 at 18:38
add comment

Possible workaround (tested on V9.0.1, Linux): just add VertexColors -> {Black} option.

Without this option I get

repeatPts[pt_, n_] := Line[ConstantArray[pt, n]]
   Graphics[{Thickness[.125], CapForm[cap], repeatPts[{0., 0.}, #], 
    repeatPts[{1., 1.}, #]}, ImageSize -> 50, Frame -> True, 
     FrameTicks -> None, PlotRangePadding -> .3] & /@ 
   Range[5] /. {{cap -> "Round"}, {cap -> "Square"}, {cap -> "Butt"}} // Grid

enter image description here

This behavior is completely unexpected: why 3 or more points differs from 1 and 2? Why in the first row the size of the points is quite different? Why we see something in the third row? (CapForm["Butt"] is the absence of the cap).

With VertexColors -> {Black} the result is much better:

repeatPts[pt_, n_] := Line[ConstantArray[pt, n], VertexColors -> {Black}]
   Graphics[{Thickness[.125], CapForm[cap], repeatPts[{0., 0.}, #], 
    repeatPts[{1., 1.}, #]}, ImageSize -> 50, Frame -> True, 
     FrameTicks -> None, PlotRangePadding -> .3] & /@ 
   Range[5] /. {{cap -> "Round"}, {cap -> "Square"}, {cap -> "Butt"}} // Grid

enter image description here

Now everything is clean: there is no line with 1 point (the first column). In the other cases this point is the cap of the line with zero length.

share|improve this answer
    
Unfortunately, in the real code that inspired this question, I need to use CapForm["Round"]. –  m_goldberg Dec 8 '13 at 1:48
    
@m_goldberg In my opinion everything is fine with CapForm["Round"]. It produces a small dot, which is about line thickness (as well as with very close points). Could you give a minimal example of your problem? –  ybeltukov Dec 8 '13 at 1:57
    
The example I gave in the question is as concise as I can make it. The result I want is no dots in any of the cases where the same point is repeated. –  m_goldberg Dec 8 '13 at 3:04
add comment

I brought this to the attention of the WRI tech support. This was their reply:

I am writing to let you know that I have reported this bad behavior to our development team. I would also like to point out (if you were not aware) that the behavior you observed is even different between operating systems (for example, in Linux the points always appear, but when more than three points are present the "point" is a square).

I conclude from this that WRI will investigate this problem as a bug, and perhaps fix it in a future release.

share|improve this answer
add comment

A bit of an obvoius hack but it does the job.

repeatPts[pt_,n_] := (If[ Length@Tally[#] == 1 , {}  , Line[#]] &@ ConstantArray[pt, n])
Graphics[{Thickness[.125], repeatPts[{0., 0.}, #], 
     repeatPts[{1., 1.}, #]}, ImageSize -> 50, Frame -> True, 
     FrameTicks -> None, PlotRangePadding -> .3] & /@ Range[5]

.. a bit faster :

 If[ Equal @@ # , {} , Line[#]] &@
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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