'Gnuplot - rectangles as objects outside graph area?

I would like get something like this:

Rectangle outside graph:

enter image description here

Could I get that with set object <number> rect ? Or is this only to draw rectangles inside graph?



Solution 1:[1]

As suggested in @ewcz's answer, you can use screen coordinates for drawing objects (partly) outside the graph area . However, if you check help object and you will find the option noclip at least since gnuplot 4.6.5. (default is clip).

With this you can draw objects outside the graph using, e.g. graph, first, second, etc. coordinates as well (check help coordinates), especially in case you want to adjust the size of your rectangle to graph or x/y-coordinates.

Script:

### draw rectangle outside graph area
reset session

set xrange [0:20]
set yrange [0:10]

set xlabel "x-axis"
set ylabel "y-axis"
set origin 0.1, 0.1
set size   0.8, 0.8

set obj 1 rect noclip from graph -0.1, 0.9 to graph 0.1, 1.1 
set obj 1 fs empty border rgb "red" lw 2 dt 4

set obj 2 rect noclip from first -2,-2 to first 7,3
set obj 2 fs empty border rgb "green" lw 2 dt 1

set obj 3 rect noclip from screen 0.6,0.6 to screen 1,1
set obj 3 fs empty border rgb "blue" lw 2 dt 3

plot x
### end of script

Result:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 theozh