1
votes

I want to plot two datasources together in gnuplot: one from a datafile, using text as x-data (with xticlabels and errorbars) and another a constant.

I don't want the xticlabels to reach the sides of the graph, so I use "set offset". However, I do want the constant to reach the sides of the graph.

An example gnuplot script:

set terminal pngcairo size 500, 500
file = 'data.txt'
set output 'plot.png'
set xtics rotate by -45
set yrange [0:1]
set offset 0.5,0.5,0,0

plot file using 0:2:3:xticlabels(1) with yerrorbars notitle,\
0.5 notitle

With the associated data.txt file:

"Europe"    0.4 0.03
"North America" 0.8 0.05
"South America" 0.1 0.08
"Asia"  0.7 0.01
"Africa"    0.9 0.03
"Australia" 0.2 0.03

Provides the following plot: Plot with constant function not reaching left/right edges

However, I want the following plot: Plot with constant function reaching left/right edges

How can I achieve this?

2

2 Answers

1
votes

You can achieve the same result if you are simply setting the xrange[] properly. In your case when using xticlabels(1), Europe=0 and Australia=5. So, simply set xrange[-0.5:5.5]. If the number of items (here 6) is unknown beforehand you could get it either via |$Data| or stats $Data and STATS_records.

Code:

### border when using xticlabels()
reset session

$Data <<EOD
"Europe"    0.4 0.03
"North America" 0.8 0.05
"South America" 0.1 0.08
"Asia"  0.7 0.01
"Africa"    0.9 0.03
"Australia" 0.2 0.03
EOD

set xtics rotate by -45

set xrange [-0.5:5.5]
set yrange [0:1]

plot $Data using 0:2:3:xticlabels(1) with yerrorbars notitle,\
    0.5 notitle
### end of code

Result:

enter image description here

1
votes

You could draw the constant as headless arrow:

set arrow from graph 0, first 0.5 to graph 1, first 0.5 nohead lt 1