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.
1 Answer
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}]
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}]
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}]
As expected, the -3 and 3 ticks are no longer there.