Menu

#2554 Misalignment of rotated multiline labels

open
nobody
None
2022-10-16
2022-10-09
theozh
No

Apparently there was a bug report from 2004 and it says it was fixed.... but obviously it wasn't or the bug reappeared.
https://sourceforge.net/p/gnuplot/bugs/194/

Script:

### how to keep alignment and line spacing with rotated multiline-labels?
reset session

set term gif animate delay 10
set output "RotatedText.gif"

set termoption font ",14"
set offset 1,1,1,1
set key noautotitle

set xrange[0:2]
set yrange[-1:5]

s = "multiline\nlabel"

do for [a=0:360:5] {
    set label 1 sprintf("Degrees:\n%g°",a) at 1,3 rotate by a
    plot '+' u (1):(1):(s) every ::0::0 w labels rotate by a right, \

}
set output
### end of script

Result: (created with gnuplot 5.4.1)

1 Attachments

Discussion

  • Ethan Merritt

    Ethan Merritt - 2022-10-09

    You are probably thinking that rotation of a multi-line label should be handled as rotation of an enclosing block that bounds the text. That's a perfectly reasonable thing to want, but it is not so easy to accomplish and gnuplot has never claimed to do that.

    From help set label:

     If `rotate` is given, the label is written vertically. If `rotate by <degrees>`
     is given, the baseline of the text will be set to the specified angle.
     Some terminals do not support text rotation.
    

    Your animation demonstrates nicely that this is exactly what happens; the angle of the baseline is rotated but the anchoring point for the text remains the same. Each line of text thus rotates about its anchoring point.

    A related point is that only some terminals can deal with rotating boxed text, even single-line text.

    Fully generalized text formatting seems way outside the scope of what gnuplot is set up to handle. It is so very dependent on the details of how each terminal handles fonts and text that I do not think a terminal-independent solution is even possible. The closest I can think of would be to construct and save a rectangular area containing a non-rotated block of text, then read that back in and display it as a rotated object. That is how the x11 terminal handles rotated text (but note that it looks really ugly). Some terminals would be able to code that using primitives of their respective support libraries (PostScript, Qt, svg, LaTeX) but that would have to be coded separately for each one and even so it would be hard to integrate with gnuplot's coordinate system, since in general gnuplot cannot get reliable text size or bounding box dimensions back from the terminal driver.

     
  • theozh

    theozh - 2022-10-10

    Thank you for this background information. Yes, this was my expectation: If I write some whatever text on a label and if I rotate this label, the text is rotated as a whole.
    ...the baseline of the text will be set to the specified angle.
    What is the baseline or anchor point of a multi-line text? The line (anchor point) of the first row or the average of the baselines (anchor points) of all lines? Apparently, a multi-line text has multiple base lines (anchor points), and as you say, all baselines (anchor points) will be treated separately.

    But if you look at the animation, why is the 2nd line jumping to its "expected" place, but only for 90° and 270° ? Maybe because these are "common" angles of rotation for axes labels in graphs? There, apparently the "average" anchor point is taken (however, not for 180°).

    Well, I can imagine that there might be complex issues with terminal drivers.
    So far, I haven't been successful in finding a workaround by splitting the multi-line labels into multiple lines and setting an individual offset by some formula. However, there is no variable offset, so I probably would have to plot the individual lines of a multi-line label in a for loop to give them individual x,y-offsets.

     
  • theozh

    theozh - 2022-10-16

    There is a workaround...
    I would say it is ok for plotted labels,
    however, not ideal, e.g. for xticlabels. At least it looks like the label is rotated and centered around the tic as a whole text box. See https://stackoverflow.com/a/74076892/7295599

     

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.