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.

How can I force the GridLines to be at the positions of the Tick marks? A simple code, FrameTicks -> Automatic and GridLines -> Automatic will do it, but not this code. The error must be in the function myTickList, but I didn't find it. Moreover, AspectRatio -> 1 seems not to work...

Result:

enter image description here

Input-File data.dat:

3542228.204 5433969.188
3542221.426 5433999.371
3 1 2 0
40

The code of the notebook:

inffile = OpenRead["data.dat"];
x1 = Read[inffile, Number]; y1 = Read[inffile, Number];
x2 = Read[inffile, Number]; y2 = Read[inffile, Number];
n1 = Read[inffile, Number]; n2 = Read[inffile, Number]; 
m1 = Read[inffile, Number]; m2 = Read[inffile, Number]; 
diff = Read[inffile, Number];
grad = Pi/2-ArcTan[y2 - y1, x2 - x1];
winkel=grad*180./Pi;
If[winkel < 0.0, winkel = winkel + 360.0];
s1 = ToString["Drehung erfolgt um "]; s2 = ToString[winkel]; 
s3 = ToString[" Grad "]; str = StringJoin[s1, s2, s3];
Style[str, FontSize -> 35, Italic, FontFamily -> "Helvetica"]
iend = n1 + n2 + 1;
Do[xkoor[i] = x1 - n2*diff + (i - 1)*diff, {i, 1, iend}]
jend = m1 + m2 + 1;
Do[ ykoor[j] = y1 + m1*diff - (j - 1)*diff, {j, 1, jend+1, 1}]
xvals = Table[xkoor[i], {i, iend}];
yvals = Table[ykoor[j], {j, jend}];
ungedreht = Outer[List, xvals, yvals] // Flatten[#, 1] & ;

myTickList[min_, max_, seg_, shift_?NumericQ, phi_?NumericQ, 
  len_: 0.01] := 
 Table[{i, 
   Rotate[Pane[Style[AccountingForm[i], LineSpacing -> {0, 12}], 
     FrameMargins -> {{shift, 0}, {0, 0}}], phi], {len, 0}}, {i, 
   If[Head[seg] === List, Union[{min, max}, seg], 
    Range[min, max, seg]]}]

r = RotationTransform[grad, {x1, y1}]; gedreht = 
 r[ungedreht];

sortiert = SortBy[gedreht, Last];

labelingfunc[v : {x_, y_, w_}, i_, ___] := 
  Placed[Grid[{{"Pflock ", i}, {"Koordinaten", 
      AccountingForm[{x, y}]}}, Frame -> All, Alignment -> Left], 
   Tooltip];
g = BubbleChart[(Append[#, 1] & /@ sortiert), ChartElements -> \!\(\*
Graphics3DBox[SphereBox[{0, 0, 0}],
Boxed->False,
ImageSize->30,
Lighting->"Neutral",
ViewPoint->{0, 
DirectedInfinity[-1], 0}]\), 
  ColorFunction -> Function[{x, y, r}, Lighter[Yellow, x]], 
  ChartLabels -> 
   Placed[Style[#, "Subsection"] & /@ Range[Length@sortiert], Center],
   BubbleSizes -> {0.07, 0.07}, LabelingFunction -> labelingfunc, 
  AspectRatio -> 1, Frame -> True, GridLines -> Automatic, 
  FrameStyle -> {Thick, Thick, Thick, Thick}, 
  GridLinesStyle -> Directive[Blue, Dashed, Thick], 
  FrameLabel -> {" Easting [m\!\(\*
StyleBox[\"]\", \"Subsubsection\"]\) ", " Northing [m] ", " ", " ",}, 
  PlotLabel -> "Grid-coordinates", 
  BaseStyle -> {FontWeight -> "Bold", FontSize -> 24}, 
  FrameTicks -> {{myTickList[Min[gedreht[[All, 2]]] - 40.0, 
      Max[gedreht[[All, 2]]] + 40., 20, 5, 0], 
     None}, {myTickList[Min[gedreht[[All, 1]]] - 40.0, 
      Max[gedreht[[All, 1]]] + 40., 20, 5, Pi/6], None}}, 
  BaseStyle -> {FontWeight -> "Bold", FontSize -> 18}, 
  ImageSize -> {800, 800}
  ]
share|improve this question
1  
The option setting GridLines->Automatic puts gridlines at major tick positions. –  kguler Aug 18 '12 at 8:24
1  
Don't be too hasty creating new tags. Tags must be maintained: you created tags but left the tag wiki empty. I know all about it; the tag system of EE.SE is a complete mess :-( –  stevenvh Aug 18 '12 at 9:56
    
of course I know this option and I used it in my code. You can see the result in this picture... It simply doesn't work –  Harald Aug 18 '12 at 10:11
5  
@Harold - "I used it in my code". You don't mention that in your question, there's just a plot. Posting your code would help. –  stevenvh Aug 18 '12 at 12:06
    
Hi, my version is 8.0.4.0 on OS X. –  Harald Aug 18 '12 at 20:09

1 Answer 1

up vote 10 down vote accepted

You can specify the GridLines by using:

GridLines -> {{x1, x2, x3,...}, {y1, y2, y3,...}}

x1,x2,y1,y2 are just your Ticks coordinates.

Here is an example:

Plot[Cos[x], {x, 0, 10}, GridLines -> {{Pi, 2 Pi}, {-1, -.5, .5, 1}},
 GridLinesStyle -> Directive[Red, Dashed], 
 Frame -> True, 
 FrameTicks -> {{0, \[Pi], 2 \[Pi]}, {-1, -.5, 0, .5, 1}},
 FrameLabel -> {"x", "Cos(x)"}]

enter image description here

Edit:

Since Harald post the code, then I post this Edit.What you need to do here is to find out the coordinates of GridLines,so I add a method called myGridList:

myGridList[min_, max_, seg_] := 
  Table[i, {i, 
      If[Head[seg] === List, Union[{min, max}, seg], 
        Range[min, max, seg]]}]

Then we can both get Grid_x and Grid_y:

gridListX = myGridList[Min[gedreht[[All, 1]]] - 40.0, 
        Max[gedreht[[All, 1]]] + 40., 20];
gridListY = myGridList[Min[gedreht[[All, 2]]] - 40.0, 
        Max[gedreht[[All, 2]]] + 40., 20];

At last, you should change GridLines->Automatic to :

GridLines -> {gridListX, gridListY}

You will get this: enter image description here

By the way, the AspectRatio->1 works well, in the picture above, you can see the length of x and y are same. If you change the value to a different one, how about 2, the picture would change: enter image description here

share|improve this answer
    
What if FrameTicks->Automatic ? –  belisarius Aug 18 '12 at 13:40
1  
@Verde If FrameTicks->Automatic then GridLines also shuold be automatic,maybe my answer was not complete –  withparadox2 Aug 18 '12 at 14:00
2  
Then edit your answer ;) –  belisarius Aug 18 '12 at 14:15
    
@Verde Why do you delete your answer,it is the complement of mine answer. –  withparadox2 Aug 18 '12 at 14:57
    
Because I thought I found a counter example where FrameTicks->Automatic, GridLines->Automatic was not working properly, but I am not able to reproduce it now –  belisarius Aug 18 '12 at 14:59

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.