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.

By default horizontal GridLines are placed in front of vertical GridLines:

style = Directive[#, AbsoluteThickness[5]] &;
Graphics[Circle[], Frame -> True, ImagePadding -> 1, GridLines -> Automatic, 
    GridLinesStyle -> style /@ #] & /@ {{LightGray, Black}, {Black, LightGray}} // GraphicsRow

Mathematica graphics

How can I place the vertical lines in front so that they appear uninterrupted?

I do not wish to resort to manually drawing Line expressions.

share|improve this question
1  
oh, my poor eyes ;-) –  Yves Klett Feb 5 '13 at 14:14
    
Uhh, much better :-) Remindeth me of: en.wikipedia.org/wiki/Grid_illusion –  Yves Klett Feb 5 '13 at 14:26
add comment

4 Answers

This at least gets the result:

style = Directive[#, AbsoluteThickness[5]] &;
Overlay[
    {Graphics[Circle[], Frame -> True, ImagePadding -> 1,
      GridLines -> Automatic,
      GridLinesStyle -> style /@ {#1, #2}],
     Graphics[Circle[], Frame -> True, ImagePadding -> 1,
      GridLines -> Automatic,
      GridLinesStyle -> style /@ {#1, Opacity[0]}]}] & @@@
  {{LightGray, Black}, {Black, LightGray}} // GraphicsRow

enter image description here

share|improve this answer
add comment

More a workaround rather than a solution, but simple and maybe useful with some pre-planning of data and such:

Rotate[Graphics[Circle[], Frame -> True, ImagePadding -> 1, 
  GridLines -> Automatic, 
  GridLinesStyle -> style /@ {LightGray, Black}], 90 Degree]

enter image description here

share|improve this answer
    
I have to admit this method did not occur to me. +1 –  Mr.Wizard Mar 2 '13 at 16:43
    
@Mr.Wizard -- Glad to help. –  Jagra Mar 2 '13 at 16:47
add comment

This is a possible way by Inset, but I'm still not very sure why it's 2.1:

style = Directive[#, AbsoluteThickness[5]] &;

Graphics[{Opacity[0], Circle[]}, Frame -> True, 
  FrameStyle -> Opacity[0], ImagePadding -> 1, 
  GridLines -> {Automatic, Automatic}, 
  GridLinesStyle -> style /@ {Opacity[0], Black}];

Graphics[Circle[], Frame -> True, ImagePadding -> 1, 
  GridLines -> {Automatic, Automatic}, 
  GridLinesStyle -> style /@ {LightGray, Opacity[0]}];

Show[%%, Epilog -> Inset[%, Center, {0, 0}, {2.1, Automatic}]]

Mathematica graphics

According to the documentation of PlotRangePadding:

PlotRangePadding->Automatic adds a total of 4% for PlotRange settings All, Full, and Automatic.

It should be $2\times (1+4\%)=2.08$, but in fact 2.08 will be worse than 2.1 here. Don't know why...

share|improve this answer
1  
You need 2.1 to allow for the default PlotRangePadding. With the option PlotRangePadding -> None you could set it to 2. –  Chris Degnen Feb 5 '13 at 15:47
    
@ChrisDegnen But why 2.1 instead of 2.08? –  Silvia Feb 5 '13 at 16:02
    
I think the ImagePadding -> 1 options throw it off. Remove them and try Show[%%, Epilog -> Inset[%, Center, {0, 0}, {2.08, Automatic}], ImagePadding -> 0]. (If I don't put in the ImagePadding -> 0 the frame is clipped, and I don't know why.) –  Michael E2 Feb 5 '13 at 16:07
    
@MichaelE2 Hmm.. interesting.. I tried changing the ImagePadding, but didn't seem to affect the 2.1 value. Get a flight to fly. Will review it tomorrow night. –  Silvia Feb 5 '13 at 16:34
add comment

I guess I'll put on paper a simple fix that works only with the gray/black lines as shown rather than being a general solution. (Desiring a general solution was the reason I originally used the garish colored lines that Yves complained about.)

style = Directive[#, AbsoluteThickness[5]] &;

Graphics[Circle[], Frame -> True, ImagePadding -> 1, GridLines -> Automatic, 
 GridLinesStyle -> style /@ {Black, Opacity[0.3]}]

Mathematica graphics

Plainly this won't work with other combinations (warning: garish colors):

Graphics[Circle[], Frame -> True, ImagePadding -> 1, GridLines -> Automatic, 
 GridLinesStyle -> style /@ {Yellow, {Green, Opacity[0.3]}}]

Mathematica graphics

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.