|
From: Aapo L. <aap...@gm...> - 2006-07-10 17:04:25
Attachments:
gnuplot-logaxis.patch
|
Hello everyone!
I found a bug in Gnuplot CVS logarithmic axis minitics in certain
user-controlled minitic settings when I was plotting a logarithmic graph
with rather long range today. The following short script highlights the
problem:
set logscale y
set ytics 10
set mytics 10
plot [0:1e3] [1:1e10] x**3
pause -1
set ytics 100
set mytics 10
plot [0:1e3] [1:1e10] x**3
pause -1
The first plot has the minitics on the logarithmic y-axis as it should;
but the second plot with ytics having a longer step doesn't show any
minitics at all. I think the 10 minitics should be there as ordered,
no? So, I hurried through the Gnuplot CVS source and found a solution
(patch attached). However, I'm not sure whether or not there are any
problems that I might have overlooked, so could someone who understands
the axis system check the problem and the patch, please? Particularly,
I'm not sure why there was a (step <= 1.5) condition - I needed to
remove it to allow larger ytics steps than 1.5 (the example has step =
2.0). As a bonus, the patch fixes a typo in comment, "but" should
probably be "bug". :-)
Best Regards, and thanks for the good plotting program
Aapo Lankinen
--- src/axis.c 2006-07-10 19:32:44.000000000 +0300
+++ src/axis.c 2006-07-10 19:35:19.000000000 +0300
@@ -976,9 +976,9 @@
minitics = 0; /* not much else we can do */
else if (axis_array[axis].log) {
/* Sep 2005 - This case has been commented out since v3.7 */
- /* but in fact it seems correct, and fixes but #1223149 */
- ministart = ministep = step / minifreq * axis_array[axis].base;
- miniend = step * axis_array[axis].base;
+ /* but in fact it seems correct, and fixes bug #1223149 */
+ ministart = ministep = AXIS_UNDO_LOG(axis,step) / minifreq;
+ miniend = AXIS_UNDO_LOG(axis,step);
} else {
ministart = ministep = step / minifreq;
miniend = step;
@@ -1137,7 +1137,7 @@
internal + mplace);
else
mtic = internal
- + (axis_array[axis].log && step <= 1.5
+ + (axis_array[axis].log
? AXIS_DO_LOG(axis,mplace)
: mplace);
if (inrange(mtic, internal_min, internal_max)
|
|
From: <br...@ph...> - 2006-07-12 21:34:08
|
Aapo Lankinen wrote: > The first plot has the minitics on the logarithmic y-axis as it should; > but the second plot with ytics having a longer step doesn't show any > minitics at all. I think the 10 minitics should be there as ordered, > no? Not really. '10 minitics' on a log-10 axis has generally been interpreted to mean the same as the default minitic placement, even though that's only 9 minitic intervals per decade. What it should mean in case the major tics are more than one decade apart is anyone's guess. Your patch would place them at arithmetic intervals (1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100), the existing code *wants* to place them at geometric intervals (i.e. graphically equidistant, but at numerically funny places, integer powers of 100^0.1), but fails. In a nutshell, I concede there's a bug, but I think you've found the wrong fix. > I'm not sure why there was a (step <= 1.5) condition - I needed to > remove it to allow larger ytics steps than 1.5 (the example has step = > 2.0). I would guess that was just because the existing code knows it would fail in that case, and thus doesn't try to continue. |
|
From: Aapo L. <aap...@gm...> - 2006-07-13 15:33:13
|
On Wed, 2006-07-12 at 23:34 +0200, Hans-Bernhard Bröker wrote: > though that's only 9 minitic intervals per decade. What it should mean > in case the major tics are more than one decade apart is anyone's > guess. Your patch would place them at arithmetic intervals (1, 10, 20, > 30, 40, 50, 60, 70, 80, 90, 100), the existing code *wants* to place > them at geometric intervals (i.e. graphically equidistant, but at > numerically funny places, integer powers of 100^0.1), but fails. Yes, it is difficult to say what should be done, when the user wants, say 12 minitic intervals on a logarithmic plot with tic interval 100. Actually, the automatic system "set mytics default" appears to work in a rather sensible fashion, but unfortunately the user requested minitics are not honoured. Also, I think that for the user requested minitics the arithmetic intervals would be better, because the user requested minitics probably aren't in "nice" places (otherwise "auto" and "default" would be used) and for awkward positions the arithmetic intervals are by far easier to read and understand. Compare e.g. 100^(x/6) and x/6*100 as tic positions. Moreover, if the tics are at arithmetic intervals, you can immediately see that the plot has a logarithmic axis without looking at the numbers. In any case, the current behaviour is inconsistent with the documentation, AND completely chaotic. See, for example, the following plots: set logscale y set ytics 10 set mytics 10 plot [0:200] [1e-3:1e8] x**3 # that's good, mtics at 10, 20, 30, ... set mytics 6 plot [0:200] [1e-3:1e8] x**3 # good, 5 mtics at arithmetic intervals set ytics 100 # "set ytics auto" has the same effect plot [0:200] [1e-3:1e8] x**3 # but now there are 2 equidistant mtics! # also, notice that minitics above 0.1 and 1 are missing! # (without changing mytics, somehow mytics went from 6 to 3?!) set mytics 2 plot [0:200] [1e-3:1e8] x**3 # no mtics ... set mytics 3 plot [0:200] [1e-3:1e8] x**3 # now it's getting weird set mytics 4 plot [0:200] [1e-3:1e8] x**3 # now we only have 1 tic ... # ... but it is actually in a sensible place, no? Of course, if you put ytics interval at something big&weird (i.e. not a power of 10), the situation only gets worse. See: set ytics 313 set mytics 13 plot [0:200] [1e-3:1e8] x**3 # tic-tic-notic-tic-skip-tic-halfskip-... or even (fortunately nobody needs these crazy intervals in practice!) set ytics 313.345637 set mytics 13.3 plot [0:200] [1e-3:1e8] x**3 # hmm > In a nutshell, I concede there's a bug, but I think you've found the > wrong fix. True. You got me thinking that maybe Gnuplot should simply discard the logarithmic minitics asked, if the logarithmic interval is not "close enough" to 1..10, as is done now. As you said, it's not clear how the minitics should be placed, arithmetically or equidistantly. However, the documentation should be modified to reflect the current behaviour; and also, the current behaviour should be fixed. The documentation simply states that you get as many mtics intervals you ask, expect that you should get one less if you ask for ten for obvious reasons (that's what you want, anyway). But it doesn't tell you that you get arithmetic mtic intervals if [xyzc]tics <= 10*sqrt(10) =~ 31.6 and equidistant otherwise. In fact, it doesn't say anything about the mtics being either arithemtic or equidistant. And, it's not possible to choose between the two modes. > I would guess that was just because the existing code knows it would > fail in that case, and thus doesn't try to continue. Perhaps. But at least some of the bugs highlighted above may be caused by the 1.5 limit. In conclusion, it might be worthwile to add command "set m[xyzc]tics arithmetic/equidistant/auto" for logarithmic axis. For linear axis it would work all right, as arithemtic and equidistant would be the same for a linear axis. Anyway, something (tm) should be done, at minimum for the documentation. Best Regards, Aapo Lankinen |
|
From: <br...@ph...> - 2006-07-14 16:04:58
|
Aapo Lankinen wrote: > Yes, it is difficult to say what should be done, when the user wants, > say 12 minitic intervals on a logarithmic plot with tic interval 100. And don't forget that the log base may well be something else than 10... 'set log y 2; set ytics 1024; set mytics 10' anyone? > Actually, the automatic system "set mytics default" appears to work in a > rather sensible fashion, but unfortunately the user requested minitics > are not honoured. That's not really the case. gnuplot does try to honour them --- otherwise the code snippets you dug up wouldn't even exist to be found, and it would not work for 'set ytics 10' either. The problem is that there's at least one bug in that (or nearby) code. > Also, I think that for the user requested minitics > the arithmetic intervals would be better, because the user requested > minitics probably aren't in "nice" places (otherwise "auto" and > "default" would be used) and for awkward positions the arithmetic > intervals are by far easier to read and understand. Tell that to the people who plot stock charts on log axes --- they *insist* on getting exactly those graphically equidistant, yet numerically unreadable tics. This part of the problem is that as soon as the axis scale isn't linear, the existing means for users to express their tic placement wishes become ambiguous. This can only be resolved by adding a new feature to 'set mxtics' & friends --- but now's really not the time to discuss, much less implement such a thing. I suggest you write a Feature Request about this proposed extension, so it can be addressed once the dust has settled on the planned 4.2 release. |