I know how to specify ticks manually. But this is too much work if you have multiple plots. I am searching a way to do that automatically. What I want to specify is the number of ticks for an axis. Is there a way to just say how many ticks you want to have? I read about "try min ticks=3" and tried "try max ticks=3" but that would have been too easy...

EDIT: Figure

Here's the figure on what I like to have 5 ticks on the y-axis.

enter image description here

  • Ok this seems to be the answer. But can I do that axis independently? – DaPhil Feb 1 '13 at 15:17
  • 1
    What do you mean with "axis independently"? You can just put \pgfplotsset{max space between ticks=50pt} in your preamble, then it will apply to all plots. – Jake Feb 1 '13 at 15:18
  • I mean, I want to have 3 ticks on x-axis and 4 on y-axis. – DaPhil Feb 1 '13 at 15:19
  • 2
    Ah, okay. You can't, unfortunately. Off the top of my head I can't really think of a situation where you would want this, though. The algorithm that determines the tick positions works pretty well, so applying the try min ticks and max space between ticks to both axes usually leads to good results. Could you provide an example of where you'd need to provide the values to the x and y axis independently? – Jake Feb 1 '13 at 15:22
  • No I can't :) I am currently just deciding how to draw figures in the future and so I want to check out the possibilities! Can I ask how the algorithm works? What if 4 ticks are ok for the y-axis but not for the x-axis? I will provide an image on where I wanted 4 ticks on the y-axis. – DaPhil Feb 1 '13 at 15:26

The tick placement algorithm works by determining the range of the axis, dividing that by the max space between ticks distance to get the desired number of ticks, and then chooses a step size of either 1, 0.5, 0.2, or 0.1 times the order of magnitude of the upper limit (so 0.1, 0.05, 0.02, or 0.01 if your largest value is something like 0.4; 100, 50, 20, or 10 if your largest value is something like 400).

So in effect, max space between ticks is used to specify how many ticks to use, but not all step sizes are allowed. This value can, at the moment, not be specified separately for the different axes (feature request?).

If you want to get step sizes of 0.25 so you can get five ticks in your example, you'll have to adjust an internal macro (or open a feature request). Putting the following chunk in your preamble will allow step sizes of 0.25 (or 2.5, or 25, etc.)

    % modify the mantisse:
                \advance\pgfmathfloat@a@E by1

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.