views:

70

answers:

1

The following plot command produces a bar chart, and above each bar the value is plotted as label, formatted with gprintf:

plot "data.txt" using 6:1 index 0 notitle with boxes linestyle 1,\
     "data.txt" using 6:(0.7):(gprintf("%5.2f", $1)) index 0 notitle \
                                       with labels font "Courier,34" rotate left

I'd like the value labels to be right-aligned so I can use the nicer-looking Helvetica font instead of Courier to align the decimal points.

So, how can I include the justification in the above command?

I failed to find anything about this specific problem in the Gnuplot documentation or on the Web. Other labels can be justified easily, but is it also possible when plotting with labels?

A: 

You specify the width of a printed field to be 5 spaces, using the "%5.2f" format. That consumes 2 spaces for fractional part, and one space for decimal point, leaving only 2 spaces for integer part of the number. So, if you plot numbers other than 0.7 that you specified, the resulted string will be wider. Also, Helvetica is a non-monospace typeface, so character widths for numbers are not the same. Thus, right-aligning the output won't solve the problem - ".11" and ".88" will not be decimal-point-aligned.

mbaitoff
This is true, the decimal points won't be aligned perfectly, but I accept a less than optimal solution if the fonts look much better.Also, I am wondering whether there might be something missing with regard to justifying labels in this particular case.
Martin Potthast
Maybe you should play with format string? Just for curiosity, try left-alignment, by using minus sign, "%-5.2f".
mbaitoff
I tried it, didn't work.
Martin Potthast