imalipusram
imalipusram

Reputation: 113

Gnuplot: Use of "graph 0" and "graph 1" when drawing rectangles

I'd be happy about some enlightenment on the use of "graph 0" and "graph 1":

Goal is to draw rectangles into a graph, but while painting the whole background works, horizontal stripes don't, when I try to use graph 0 and graph 1 to indicate the left and right boundaries.

I'm following the second example at http://gnuplot.sourceforge.net/demo/rectangle.html

reset session
set xrange [0:6]
set yrange [0:25]

set obj 1 rect from graph 0,graph 0 to graph 1,graph 1 fc "red"   # paint the background

set obj 2 rect from graph 0,5 to graph 1,12 fc "green"            # produces nothing

set obj 3 rect from 'graph 0', 3 to 'graph 1',10 fc "blue"        # produces nothing 

set obj 4 rect from 'graph 0', 4 to 6,8 fc "yellow"               # this works. '...' and 6 required 

plot 'data02.txt'

What am I missing?

My gnuplot is 5.2.8 on Ubuntu 20.04.4 LTS

Thanks for your help!

Upvotes: 1

Views: 170

Answers (1)

theozh
theozh

Reputation: 26068

Why do you write e.g. 'graph 0' instead of graph 0? And check help coordinates:

If the coordinate system for x is not specified, first is used. If the system for y is not specified, the one used for x is adopted.

Hence, e.g. graph 0, 5 and graph 0, 12 will be outside of the graph. You should write graph 0, first 5 and graph 0, first 12 or 0,5 and 0,12 if you mean the x- and y-coordinates. Actually, in your case graph 0 is identical with first 0. So, it depends what you want.

Check the following script.

Script:

### coordinate sytems graph and first
reset session

set xrange [0:6]
set yrange [0:25]

set obj 1 rect from graph 0,       0 to graph 1,        1 fc "red"
set obj 2 rect from graph 0, first 5 to graph 1, first 12 fc "green"
set obj 3 rect from graph 0, first 3 to graph 1, first 10 fc "blue"
set obj 4 rect from graph 0, first 4 to       6,        8 fc "yellow"

plot NaN notitle   # or plot some data
### end of script

Result:

enter image description here

Upvotes: 2

Related Questions