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:
¹ ⁾ 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)
You can get that by saying
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
orset 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.[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.]
The case of very wide ranges: R ≥ 10¹⁰
This one is very straightforward for ranges R up to 10¹⁰⁰:
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:
This covers all cases with R ≥ 6 or R ≤ 2.5.
[Need to think more about what to do in the remaining interval.]
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):
[n:n+30]
put major ticks at integers, labels at even integers, and minor ticks at half-integers¹⁾.[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.