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 am graphing the voltage traveling through some water with two electrodes. I have the graph with contour lines and all, but is there any way that I can get the contour lines to be at the tick marks along the Z axis?

So, if every tick mark is 1volt, can I have contour lines at every integer voltage?enter image description here

share|improve this question

2 Answers 2

up vote 6 down vote accepted
 data = Table[Sin[j^2 + i], {i, 0, Pi, 0.1}, {j, 0, Pi, 0.1}];
 zmesh = {-1/3, 0, 1/3};
 facegrids =  Thread[{Join[
 IdentityMatrix[3], -IdentityMatrix[3]], {Range[5, 30, 5], zmesh}},    List, 1];
 ListPlot3D[data, MeshFunctions -> {#3 &}, Mesh -> {zmesh},
 FaceGrids -> facegrids, BoxRatios -> {1, 1, 1/2},  PlotRangePadding -> 0]

enter image description here

share|improve this answer
    
Seems like there's a lot of extra in this answer, but by using Mesh -> {Range[max]} it worked. –  Keegan McCarthy Jan 28 '13 at 23:12

This adapts the ticks and the mesh to the range of the $z$ values:

data2 = Table[10 + (3 ((j - 20)^2 - (j + 5)^2))/(75 + (i - 10)^2 + 2 (j - 10)^2),
          {i, 0, 20}, {j, 0, 20}];

(* computes ticks and stores the coordinates in zmesh *)
ticks[zmin_, zmax_] := Module[{mark, ldz, dz},
   ldz = Round[Log10[(zmax - zmin)/10], 1/3];
   dz = Round[10^ldz, 10^Floor[ldz]];
   mark = Round[10^(ldz + 2/3), 10^Floor[ldz + 2/3]];
   If[Chop@Mod[#, mark] == 0, #, {#, "", {0.005, 0}}] & /@ (zmesh = 
      N@Range[Ceiling[zmin, dz], zmax, dz])];

myTicks = ticks[Min[data2], Max[data2]]; (* sets mesh & ticks to same z-values *)

ListPlot3D[data2, MeshFunctions -> {#3 &}, Mesh -> {zmesh}, 
 BoxRatios -> {1, 1, 1/2}, PlotRangePadding -> 0, FaceGrids -> All, 
 Ticks -> {Automatic, Automatic, myTicks}]

Output

This is kind of cute, except ListPlot3D evaluates twice, since zmesh is reset by the function ticks. But perhaps that's ok if you have the spare time.

Dynamic@ListPlot3D[data2, MeshFunctions -> {#3 &}, Mesh -> {zmesh}, 
  BoxRatios -> {1, 1, 1/2}, PlotRangePadding -> 0, FaceGrids -> All, 
  Ticks -> {Automatic, Automatic, ticks}]

It also works with other plot functions

Dynamic@Plot3D[5 Sin[x^2 + x y^2/2]/(1 + x^2 + y^2),
  {x, -3, 3}, {y, -3, 3}, MaxRecursion -> 3, MeshFunctions -> {#3 &}, Mesh -> {zmesh}, 
  BoxRatios -> {1, 1, 1/2}, PlotRangePadding -> 0, FaceGrids -> All, 
  Ticks -> {Automatic, Automatic, ticks}]

Output

share|improve this answer

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.