2
$\begingroup$

Is there any way I could use the MaxStepFraction (or grid size) as used in NDSolve in the example below as ticks on the 3d Plot?

That was I would be able to plot the grid points on the X and Y axis.

I tried creating a table and using that as the argument in Ticks but that didn't work.

Minimum working example:

Clear[u, L, t, x, y, sol, Eq]
L = 4;
Eq = -D[u[t, x, y], t, t] + D[u[t, x, y], x, x] + 
   D[u[t, x, y], y, y] + Sin[u[t, x, y]];
uSol = u /. NDSolve[{
     Eq == 0, u[t, -L, y] == u[t, L, y], 
     u[t, x, -L] == u[t, x, L], 
     u[0, x, y] == Exp[-(x^2 + y^2)], 
     Derivative[1, 0, 0][u][0, x, y] == 0
     }, 
    u,
     {t, 0, L/2}, {x, -L, L}, {y, -L, L},
    MaxStepFraction -> 1/11
    ][[1]]




tt = 1.2;
Plot3D[ uSol[tt, x, y], {x, 0, L}, {y, 0, L}, 
 Ticks -> {{0, 2/5, 4/5, 6/5, 8/5, 2, 12/5, 14/5, 16/5, 18/5, 4}, {0, 
    2/5, 4/5, 6/5, 8/5, 2, 12/5, 14/5, 16/5, 18/5, 4}}]

enter image description here

The ticks in the above figure were created using, Table[i 4/10, {i, 10}] and then manually pasted into the curly brackets. Obviously, that isn't the most efficient way.

I tried pasting the Table command inside Plot3D but that didn't work.

$\endgroup$
  • $\begingroup$ Try Ticks -> Evaluate[{Table[(* stuff *)], (* other ticks *)}]; Plot3D[] is HoldAll, see... $\endgroup$ – J. M.'s technical difficulties Sep 25 '12 at 13:45
  • $\begingroup$ @J.M. Evaluate.... hmm... I never thought of that. This isn't the first time I've come across this Evaluate... $\endgroup$ – dearN Sep 25 '12 at 13:49
  • $\begingroup$ @J.M. Are my questions really poor? I thought I'd ask. $\endgroup$ – dearN Sep 25 '12 at 13:49
  • $\begingroup$ Well, they aren't poor per se... I suppose the HoldAll attribute of plotting functions isn't really obvious at first glance. $\endgroup$ – J. M.'s technical difficulties Sep 25 '12 at 14:00
  • 3
    $\begingroup$ @drN Can you point out, why Table didn't work? For me something like Plot3D[uSol[tt, x, y], {x, 0, L}, {y,0, L}, Ticks -> Table[x, {3}, {x, 0, 4, 1/3}]] does work, even with the HoldAll attribute of Plot3D. $\endgroup$ – halirutan Sep 25 '12 at 19:14
2
$\begingroup$
tt = 1.2;
Plot3D[uSol[tt, x, y], {x, 0, L}, {y, 0, L}, 
      Ticks -> {Table[i 4/10, {i, 10}], Table[i 4/10, {i, 10}]}
]

or the slightly more concise version of mr.wizard:

Plot3D[uSol[tt, x, y], {x, 0, L}, {y, 0, L}, 
  Ticks -> ({#, #} & @ Table[i 4/10, {i, 10}])
]

yield:

Mathematica graphics

or, since you wanted to use your setting for MaxStepFraction (1/11), you could use FindDivisions with that value:

tt = 1.2;
Plot3D[uSol[tt, x, y], {x, 0, L}, {y, 0, L},
      Ticks -> {FindDivisions[{0, L, 1/11}, 10],FindDivisions[{0, L, 1/11}, 10]}
]

Mathematica graphics

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Looks like I lost. If you add the concise {#, #} form I'll delete my answer. $\endgroup$ – Mr.Wizard Sep 26 '12 at 9:18
  • $\begingroup$ @Mr.Wizard ;-P Looks like it. Perhaps time to go to bed? $\endgroup$ – Sjoerd C. de Vries Sep 26 '12 at 9:20
  • 1
    $\begingroup$ Why do you need such a big Function construct? Was Table[i 4/10, {2}, {i, 10}] too simple? ;-) $\endgroup$ – halirutan Sep 26 '12 at 10:03
  • $\begingroup$ This is definitely a good answer like the other one :P. However, haliurtan's answer/comment is simplicity itself. I don't quite understand why it didn't work previously. $\endgroup$ – dearN Sep 26 '12 at 13:59
  • $\begingroup$ @drN No! A single Table doesn't give the ticks as you showed in the figure in your question. Besides, you'd need to place {} around it, otherwise you'd get errors. (that might even have been the error that plagued you) $\endgroup$ – Sjoerd C. de Vries Sep 26 '12 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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