formatting tic label that are read from the datafile

formatting tic label that are read from the datafile

Post by marko.van. » Fri, 23 Jan 2009 05:46:15


Hi all,

I have a problem with a gnuplot script that worked with a previous
version of gnuplot (an experimental 4.1 version I believe), but which
no longer works with the current version.

The script contains the following plot command:
"" every ::2:0:2:3 using 1:2:y2ticlabels("%.1s \\percent") with
points 0, \

This used to read the y2 tic labels (which are numbers like 9.63 )
from the file, and processed them with the given formatting string.
The resulting label for 9.63 would then be "10 \percent". The current
version of gnuplot no longer processes the labels, but uses the
formatting string itself as the tic label. Using 'set format y2 ...'
does not work either. Does anyone know how to achieve this with the
current version of gnuplot? The datafile is generated from an
OpenOffice.org spreadsheet, and it would be very inconvenient if I
have to change the original data.

Regards,

Marko
 
 
 

formatting tic label that are read from the datafile

Post by sfea » Fri, 23 Jan 2009 06:11:01


To the best of my knowledge, no version of gnuplot has ever accepted
the command you show. It is unclear to me where it is expecting to read
this y2ticlabel number from. From column 3? from column 2? Some other
file? The command is also problematic as written because it does not
specify that the y2 axis is to be used at all, so there is no axis
to which one might attach these axis tic labels.

Please go back to the beginning, and describe exactly what is in your data
file, and what you would like to appear on your plot.

 
 
 

formatting tic label that are read from the datafile

Post by Mark » Fri, 23 Jan 2009 06:54:41

> To the best of my knowledge, no version of gnuplot has ever accepted

The version I used at the time was no official version of gnuplot. I
compiled it from a CVS checkout from the development version 4.1.

The part of the datafile used in that line is:

1 2.94
2 12.13
3 9.91
1 21.42
2 34.33
3 35.58
1 -9.3
2 -5.03
3 -6.26
1 10.77
2 17.21
3 15.2


The first column is the x value, the second column is the y value. I
want the y values at x=1 as the y tics (-9.3, 2.94, 10.77, 21.42) and
the y values of x=3 as the y2 tics (-6.26, 12.13, 15.2, 35.58). Now,
because the last decimal is not important in the plot I need, I want
to format them such that I get (-9.3, 2.9, 10.8, 21.4) for the y tics
and (-6.3, 12.1, 15.2, 35.6) for the y2 tics. With the CVS version
from somewhere in 2006, I could do that for the y2 tics with the
following line:

"" every ::2:0:2:3 using 1:2:y2ticlabels("%.1s \\percent") with points
0, \

Because 'set format y2' did not work, I just put the formatting as in
the line above, and at that time it worked wonderfully. The output can
be seen in the following PDF at page 19 (y2 tic labels of right plot
(except the 0% which was added separately)):
http://www.yqcomputer.com/ ~marko/ecoop2007.pdf
 
 
 

formatting tic label that are read from the datafile

Post by Mark » Fri, 23 Jan 2009 06:57:48


I want

I forgot the "%" character, which I also wanted in the tic label. The
self defined *** \percent command inserts it (at the time I could
not figure out how else to do that). According to the scanf
documentation, "%.1s \\percent" is what I needed.
 
 
 

formatting tic label that are read from the datafile

Post by sfea » Fri, 23 Jan 2009 11:54:14


What you describe is not quite possible, and I remain skeptical that
your earlier version of gnuplot worked as you describe.

The y2ticlabels option reads a string, and the format you show writes
a string, so neither on input nor output is it possible to do correct
rounding. That is 3.2 and 3.9 will both print as "3".

If you are willing to simply print the numbers as they appear in the file,
then it is sufficient to say:

"" axes x1y2 using 1:2:y2ticlabels(2)

If you want a % character after the string, you can do something like

"" axes x1y2 using 1:2:y2ticlabels( sprintf("%s%%",stringcolumn(2)) )

possibly modified for use with LaTeX.

Note that it is in general necessary to include "axes x1y2", because
otherwise there is no guarantee that the position of ticmarks along the
y2 axis will match the position of the points, which are being plotted
on the y1 axis. There are other ways to force this, but you do not
mention using them so I just want to point this out.
 
 
 

formatting tic label that are read from the datafile

Post by Mark » Fri, 23 Jan 2009 20:15:11


I dug up the gnuplot version on my old Powerbook. It is version 4.2-
rc1. I compiled it again on my new laptop, and it works exactly the
way I described.

./configure --prefix=/sw --enable-datastrings
make
sudo make install

I have put all the files online so anyone can try it for themselves.

http://www.yqcomputer.com/ ~marko/data.reduction.gnuplot
http://www.yqcomputer.com/ ~marko/data.domainreduction.gnuplot
http://www.yqcomputer.com/ ~marko/data.loc.gnuplot
http://www.yqcomputer.com/ ~marko/plot (this is the gnuplot
script)
http://www.yqcomputer.com/ ~marko/gnuplot-4.2.rc1.tar.gz (this is the
original RC1 source tarball)

With this version, you will find values with 1 decimal in
reduction.tex . With version 4.2.4 you will find the formatting string
of the script at the same place (and since it contains a %, the latex
file is invalid).

I can generate my plots again, but I wonder why they removed that
feature. I makes little sense to me to allow formatting of labels that
come from a function, but not allow formatting of labels that are read
from a file.

Regards,

Marko
 
 
 

formatting tic label that are read from the datafile

Post by sfea » Sat, 24 Jan 2009 02:32:46


Thank you for providing the complete set of scripts and files.

The change in behavior that you are noticing happened between
4.2.3 and 4.2.4 (i.e. sometime between March 2008 and September 2008).

The only entry in the ChangeLog for this period that appears at all related
to axis tic labels is this one:

2008-07-25 Ethan Merritt < XXXX@XXXXX.COM >
* src/datafile.c (plot_ticlabel_using): If tic labels will be generated
from an expression then force evaluation of all column contents.
Otherwise references to column() return uninitialized garbage. Bugfix.

I don't really understand why that would produce exactly the change you see,
but never mind that. As best as I can figure out what was happening, your
script contained an error that was happily counter-acted by an error in the
program. The basic error is that your plot commands never told the program
where to find the y2 tic labels. Luckily, the "uninitialized garbage"
referred to in the ChangeLog just happened to contain the quantity you
wanted, probably because it was left over from processing the previous
using spec.

There was also a confusion between whether the tic labels are to be handled
as strings or as numbers, but let's leave that aside for now.


I believe that the proper fix is something like this:

old:
"" every ::2:0:2:3 using 1:2:y2ticlabels("%.1s \\percent") with points 0, \
fix:
"" every ::2:0:2:3 using 1:2:y2ticlabels(sprintf("%.1f \\percent",column(2)) with points 0, \


column(2) forces it to read the value you want _as a number_
the sprintf() statement then reformats it to use one decimal place, returning a string
the y2ticlabels() function wants a string as input, so it is now happy



This may be one of those rare cases where one user's "bug" really is another
user's "feature". I think your script was happily taking advantage of a bug
that was fixed last July.

Having said that, I am still concerned that the script you provided fails to
guarantee that the y1 and y2 axes are exactly in sync. You should either add
the "axes x1y2" clause to the using spec, or explicitly initialize the two sets
of axes to the identical range:

set yrange [ymin:ymax]
set y2range [ymin:ymax]
 
 
 

formatting tic label that are read from the datafile

Post by Mark » Sat, 24 Jan 2009 08:14:01

> I believe that the proper fix is something like this:
> fix>
> " every ::2:0:2:3 using 1:2:y2ticlabels(sprintf("%.1f \\percent",column(2)) with points >, >
>
> column(2) orces it to read the value you want _as a nu>ber_
> the sprintf() statement then reformats it to use one decimal place, returning a >tring
> the y2ticlabels() function wants a string as input, so it is no> h>ppy
>
> This may be one of those rare cases where one user's "bug" really is >nother
> user's "feature". think your script was happily taking advantage o> a bug
> that was fixed las> J>ly.
>
> Having said that, I am still concerned that the script you provided f>ils to
> guarantee that the y1 and y2 axes are exactly in sync. ou should eit>er add
> the "axes x1y2" clause to the using spec, or explicitly initialize the t>o sets
> of axes to the identical>ra>ge:
>
> et yrange ymi>:ymax]
> et y2range [ymin:ymax]

That seems logical indeed. Thank you for the help! I was confused
because
my old script accidentilly did what I wanted back then; I remember I
stumbled
upon the "solution" by trial and error. That's also why it took me a
while to understand
my own script after not using it for more than a year. Your version
makes sense; I now see
why it shouldn't work the way I did it. Now I can go plotting again
with the latest gnuplot. Thanks!

Regards,

Marko