15
$\begingroup$

So as of now I am using

Ticks -> {Range[0, d, 1]}

where d is the maximum value for my axes.

But the thing is that between 0 and 1 (or other integers) there are no minor ticks. Look here.

I have now only the integers and empty space in between. All I want is to have like five minor ticks. Just so that it looks better. I want to have the major (labeled) ticks only at the integers.

Also could maybe someone tell me how to not have two 0 labels on one plot (one for the x-axis, one for the y-axis)? Again look here.

I've spent an hour looking for the solution, but wasn't able to find a good one.

$\endgroup$

1 Answer 1

16
$\begingroup$
Plot[1 + x^2, {x, 0, 5}, 
 Frame -> {{True, False}, {True, False}}, 
 PlotRangePadding -> 0, 
 FrameTicks -> {{Charting`ScaledTicks["Linear"][0, 25, {5, 5}], 
    None}, {Charting`ScaledTicks["Linear"][0, 5, {5, 5}], None}}]

enter image description here

To remove one of two ticks with label 0 at the origin use

FrameTicks -> {{Charting`ScaledTicks["Linear"][0.5, 25, {5, 5}], 
   None}, {Charting`ScaledTicks["Linear"][0, 5, {5, 5}], None}}

enter image description here

You can also create a custom tick function to use with FrameTicks:

tickFunc = Join[{#, #, {.03, 0}} & /@ Subdivide[##, 5], 
     {#, " ",  {.01, 0}} & /@ Subdivide[##, 25]] &; 

Plot[1 + x^2, {x, 0, 5}, 
 Frame -> {{True, False}, {True, False}}, PlotRangePadding -> 0, 
 FrameTicks -> {{tickFunc, None}, {tickFunc, None}}]

enter image description here

$\endgroup$
8
  • $\begingroup$ Worked like a charm! thank you $\endgroup$ Commented Jan 30, 2019 at 20:37
  • $\begingroup$ @kglr Trying to extend your first technique for use on a 3D plot gives the error: "A tick position in the value of the Ticks option should be a number." How can your first technique be correctly extended for use with a 3D plot? $\endgroup$ Commented Oct 1, 2019 at 18:45
  • 2
    $\begingroup$ @MichaelB.Heaney, this works: Plot3D[1 + x^2+y^2, {x, 0, 5},{y, 0,5}, Ticks -> {Charting`ScaledTicks["Linear"][0,5, {5, 5}], Charting`ScaledTicks["Linear"][0, 5, {5, 5}],Charting`ScaledTicks["Linear"][0, 50, {2, 5}]}] $\endgroup$
    – kglr
    Commented Oct 2, 2019 at 0:03
  • 1
    $\begingroup$ @CATrevillian, thank you for bringing this to my attention. I updated with a method that removes one of the duplicate labels at the origin. $\endgroup$
    – kglr
    Commented Apr 5, 2020 at 3:21
  • 1
    $\begingroup$ Side note: syntax of Charting`ScaledTicks has changed a bit in higher versions. See: mathematica.stackexchange.com/a/269044/1871 $\endgroup$
    – xzczd
    Commented Nov 26, 2022 at 5:33

Your Answer

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

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