Menu

#2717 (Minor) Ticks on the log axes [Still completely broken in 6.0]

None
closed-fixed
nobody
None
2024-12-21
2024-06-21
No

In #2372 @sfeam Ethan Merritt wrote:

I think this is not a bug, because I don't think there is any reasonable set of positions for minor tics in this case.

Of course there is a reasonable set of positions for minor tics! Just put them were users expect them. Example: with

set autoscale noextend; set logscale y; plot [1.1:1.9] x

the ticks should be put on the y-axis at exactly the same coordinates as on the x-axis.

The general ruleset to make things as intuitive as possible:

  • Typically, at least 4 major ticks with attached numbers should be present.
  • In a few very exceptional situations, one may allow decreasing this count down to 3.
  • For best result, there should be 3 gradations:
    • Major ticks with attached coordinates;
    • Major ticks w/o attached coordinates¹⁾ ;
    • Minor ticks²⁾;
  • In my experience writing tick-positioners for other software, there should be at most 15 attached coordinates.
  • Most probably, one should skip minor ticks if their count is ≳100. (Same for majors-w/o-coords.)

¹ ⁾ These are rarely needed with linear scale; may be needed if the range is very narrow, so a lot of decimals are needed, as in [1.00000001:1.00000002]. Needed in log-scale when the range is ≥10¹⁵. (When the range turns out to be ≥10¹⁰⁰, one may need to start to position them sparsely, like every ×100, then ×10000, then ×10¹⁰ etc.
² ⁾ with linear scale, at ⅒⸣s — or at ⅕⸣s — or at ½; same with log-scale when it is “almost linear” (as when max/min≤3); with “non-linear” log-scale: either omit, or — depending on the distance between a particular pair of major ticks, put at 2·10 ⁿ and at 5·10 ⁿ (these should be positioned at least ¹⁄₁₀₀ of the plot width apart).

(Based on these rules, it is easy to write pseudo-code for the logic. Let me know if this is needed.)

(I could not answer before due to #2398)

Discussion

  • Ethan Merritt

    Ethan Merritt - 2024-06-22

    the ticks should be put on the y-axis at exactly the same coordinates as on the x-axis

    You can get that by saying

    set autoscale noextend; set logscale y;
    set ytics 0.1 nolog
    plot [1.1:1.9] x
    

    I agree that looks nice. As it stands you have to specify a tick internal in this case, but I think I know how to fix that. Can you test the attached patch?

    The question then becomes "how should the program know when to do this by default?". You've obviously put some thought into this. Do you have a suggestion for an empirical set of conditions under which the auto-placement of ticks onto an axis should default to "nolog" even though the axis is log-scaled, and what the tick spacing should be? Your 2nd footnote mentions (max/min<3) but if I understand correctly that was for minor ticks and by itself doesn't provide a spacing, only a threshold at which the program might switch to linear rather than log tick placement.

    The original issue #2372 was more specifically an issue with minor tick levels, which may be a separate question. For that example the major tick placement comes out the same whether you ask for set ytics log or set ytics nolog. I asked then and ask again now whether you agree that in that example it would be better to turn off the minor ticks altogether, based on the major tick interval exceeding some threshold in log scale.

     
  • Ilya Zakharevich

    [Right now I won’t be able to test patches. Are there daylies for Windows 7?]

    [Cannot see nolog documented]

    Finally, here is the start of pseudo-code, now only for the bugs which may be fixed by switching the defaults for tick locations:
    - The “current” log-logic is OK as far as at least 4 major ticks are put on the axis. It switches to a buggy “too dense” branch (approximately) when the range exceeds 10¹⁰. So one needs only to cover the case of ranges more narrow than 10⁴ and wider than 10¹⁰.
    - The presumed nolog mode should be OK (hence the default) if at most 15 positions are shown in this mode. Essentially, this covers the case of ranges more narrow than [n:n+15] with 1≤n≤10 (or 10ⁿ times such ranges).

    For best result, the later code should be corrected for the placement of minor ticks to be “variable”: say, on [1.1:9.9] the minor ticks may be placed at ⅒⸣s up to say 3 (“the middle”), then at ⅕⸣s up to 6, and then at ½. (To worry less about these numbers, one policy may be to “code in expectation that eventually these numbers may be ‘user-tunable’”.)

    Or maybe:
    - where the step between major ticks is <¹⁄₁₅ of the total width, switch from ⅒⸣s to ⅕⸣s;
    - where it is <¹⁄₃₀, switch to ½.

    [I promise to return to the other cases later.]

     
  • Ilya Zakharevich

    The case of very wide ranges: R ≥ 10¹⁰

    This one is very straightforward for ranges R up to 10¹⁰⁰:

    • For R < 10³⁰ put major ticks at powers of 10.
    • For 10³⁰≤R<10¹⁰⁰ put major ticks at the labelled powers of 10, and minor ticks at unlabelled.
    • Put labels at powers of 10ⁿ where n is the minimal such that 10¹⁵ⁿ > R.
    • For R < 10²⁰ put minor ticks at even·10ᵐ;
    • For 10²⁰ ≤ R < 10³⁰ put minor ticks at 2·10ᵐ and 5·10ᵐ.
    • For 10¹⁰⁰ ≤ R put major and minor ticks exactly as now in linear mode — only labelled as 10ᵏ instead of k.
     
  • Ilya Zakharevich

    This leaves the case of R between about 2.5 and 10000 uncovered. The worse offender is the
    interval like [2.01:49]. On this inverval even putting labels on ticks at 2·10ᵐ and 5·10ᵐ gives only 3 labelled positions: at 5, 10 and 20. This example shows that:

    • If R ≥2.5 and there are less than 4 powers of 10 in the range, then try to label ticks for 2·10ᵐ and 5·10ᵐ (making them major too). If there are 4 or more, stop.
    • Otherwise do the same with 10ᵐ and even·10ᵐ. If there are 4 or more, stop.

    This covers all cases with R ≥ 6 or R ≤ 2.5.

    [Need to think more about what to do in the remaining interval.]

     
  • Ilya Zakharevich

    AFAICS, the remaining yet-uncovered cases are covered by these two recipes (which — as above — put ticks at reasonable positions, while keeping the count of labels between 4 and 15):

    • For ranges up to [n:n+30] put major ticks at integers, labels at even integers, and minor ticks at half-integers¹⁾.
    • Otherwise, for ranges up to [n:n+50] put major ticks at integers, labels at integers divisible by 5, and no minor ticks.

    Likewise for 10ⁿ-rescalings of such intervals.

    ¹ ⁾ Alternatively, use the general rules state above for the placement of minor ticks.

     
  • Ethan Merritt

    Ethan Merritt - 2024-06-27
    • status: open --> pending-fixed
     
  • Ethan Merritt

    Ethan Merritt - 2024-12-21
    • Status: pending-fixed --> closed-fixed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.