Search code examples
objectrotationgnuplotrectangles

It's possible to rotate an object in gnuplot?


I'm using software that uses Gnuplot language to plot some data, but I've never used Gnuplot before.

So I was trying to place labels and rectangles in a way that created a nice and readable text, which wasn't bad (as you can see with the number 182 in the image below), but I wanted to learn how to rotate the rectangle and label so that they line up with the white line.

(I can't post images, but it's like that in this link Right now, it looks like:

Example)

I've already learned to rotate the label (as you can see the number 171), but apparently, it doesn't work the same way with the object.

# setting the label and rotating it works
set label 1 "TEXT" at 10, 20 center rotate by 30 front
# setting the object works
set object 1 rect center 10,20 size 1,2 front
# But this doesn't work
set object 1 rect center 10,20 size 1,2 rotate by 30 front
# this line return the error message "Unrecognized or duplicate option"

The important part of my code that sets a rectangle and a label is here below:

x1 = 2979
x2 = 3140
y1 = -225
y2 = -168
ang = 19.9275
h = 30
w = 60
# set object 1 rect center (x1+x2)/2,(y1+y2)/2 size w,h rotate by ang front fillcolor "black" fillstyle transparent solid 0.5 noborder
set object 1 rect center (x1+x2)/2,(y1+y2)/2 size w,h front fillcolor "black" fillstyle transparent solid 0.5 noborder
set label 1 sprintf("{/:Bold %1.0f}",sqrt((x2-x1)**2 + (y2-y1)**2)) at (x1+x2)/2,(y1+y2)/2 center rotate by ang front tc rgb "white"
set arrow from x1,y1 to x2,y2 heads size 10,90 front linecolor rgb "white" linewidth 2.5 dashtype 6

So how do I rotate the rect object? And if it's not possible, is there another way to do this (other than having to manually set a polygon)?


Solution

  • Check the following example and help labels. You can create a datablock and add your labels and plot them rotated and boxed together with your map.

    Edit: ...forgot the semitransparent boxes. You need to play with the alpha channel, i.e. 0xAARRGGBB.

    Code:

    ### boxed semitransparent text labels
    reset session
    
    # create some background test data
    f(x,y)=(sin(1.3*x)*cos(.9*y)+cos(.8*x)*sin(1.9*y)+cos(y*.2*x))*3+15
    set samples 51
    set isosamples 51
    set table $Data
        splot [0:600][0:600] f(x/60.,y/60.)
    unset table
    
    $myLabels <<EOD
    # text x   y   a
    171    300   300   45
    182    100   500   90
    197    500   400   60
    333    400   100  -30
    EOD
    
    set style fill transparent solid 1.0 noborder
    set style textbox opaque fc rgb 0xaaffffff noborder
    set angle degrees
    set key noautotitle
    
    plot $Data u 1:2:3 with image palette,\
         $myLabels u 2:3:1:4 w labels rotate var boxed font ",24"
    ### end of code
    

    Result:

    enter image description here