2

I am trying to draw a rudimentary line segment from (0,0) to (0,1). I already have an input file, but I want to add a line to it.

I have read through Line plot in GnuPlot where line width is a third column in my data file? and Plot line segments from a datafile with gnuplot among many other examples. Everyone is doing something much more complex than what I want, I only want the line segment added to my GNUPlot script.

I normally enter the data in to GNUPlot thus:

$DATA << EOD
.... other data
EOD
$LS << EOL
0   0
0   1
EOL
plot $DATA using 1:2:3 with points
plot $LS with lines

but this doesn't work, nor does

plot $LS using 1:2 with lines

How can I plot this simple line segment from (0,0) to (0,1)?

2 Answers 2

4

You can use headless arrows to plot arbitrary line segments.

set xrange [0:1]
set yrange [0:1]
set arrow 1 from 0,0 to 0,1 nohead lw 3 lc 2
set arrow 2 from 0,0 to 1,1 nohead lw 2
plot NaN t''

resulting plot

Sign up to request clarification or add additional context in comments.

1 Comment

combining with plot $DATA like in the question, only set arrow... is needed
4

What does "doesn't work" mean? You don't even show the resulting graph. By the way what do you use the 3rd column for?

Your first example will make a plot only with your data and then a new plot with only the line segment. And in your second example, the line from 0,0 to 0,1 in your plot is identical with the y-axis and therefore hard to see as long as the xrange starts from 0. You can easily check this, e.g. if you set the color to red or linewidth to 3 , e.g.

plot $LS u 1:2 lc "red" lw 3

You also can make your line segment "visible" if you set xrange[-0.2:]. Check the following example

Code:

### plotting simple line segments
reset session

$DATA << EOD
0.1  0.2  1
0.3  0.4  2
0.5  0.6  3
0.7  0.5  4
EOD

$LS1 << EOL
0   0
0   1
EOL

$LS2 <<EOL
0   0
1   1
EOL

set xrange [-0.2:]

plot $DATA using 1:2:3 with points pt 7, \
     $LS1 u 1:2 with lines, \
     $LS2 u 1:2 with lines
### end of code

Result:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.