2
$\begingroup$

Is there a way to drop some of the ticks automatically produced by Mathematica in a 3D plot? I would like to drop, say, the first one of the z-axis since it overlaps with the last one of the y-axis.

$\endgroup$
1
  • 3
    $\begingroup$ An illustrative example would be welcome. $\endgroup$ Nov 13, 2019 at 16:06

1 Answer 1

4
$\begingroup$

You can use the undocumented Charting`FindTicks to generate ticks automatically and then remove the ones you don't want. That's more or less the same as taking the default ticks and removing some of those.

I learned about Charting`FindTicks from Mr. Wizard's answer here.

Start with a basic plot:

plot = Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}]

Mathematica graphics

Now use Charting`FindTicks to generate ticks for it:

{xticks, yticks, zticks} = Charting`FindTicks[{0, 1}, {0, 1}] @@@ PlotRange[plot];
Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, Ticks -> {xticks, yticks, zticks}]

Mathematica graphics

It didn't generate exactly the same ticks as the default ticks function, but it's close. If you inspect e.g. xticks now, you'll see a list of major and minor ticks:

{{-3., -3}, {-2., -2}, {-1., -1}, {0., 0}, {1., 1}, {2., 2}, {3., 
  3}, {-3., "", {0.005, 0.}, {AbsoluteThickness[0.1]}}, {-2.8, 
  "", {0.005, 0.}, {AbsoluteThickness[0.1]}}, {-2.6, 
  "", {0.005, 0.}, {AbsoluteThickness[0.1]}}, {-2.4, 
  "", {0.005, 0.}, {AbsoluteThickness[0.1]}}, ...

You can now remove ticks you don't want. Let's say that you don't want the -3 and 3, then you can do this:

xticks = xticks /. {{-3., -3} -> Nothing, {3., 3} -> Nothing};

Let's confirm that they're gone:

Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, Ticks -> {xticks, yticks, zticks}]

Mathematica graphics

As expected, the -3 and 3 ticks are no longer there.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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