agam
agam

Reputation: 5394

How do I draw a set of vertical lines in gnuplot?

E.g. if I have a graph and want to add vertical lines at every 10 units along the X-axis.

Upvotes: 43

Views: 138891

Answers (5)

Nicholas
Nicholas

Reputation: 673

From the Gnuplot documentation:

To draw a vertical line from the bottom to the top of the graph at x=3, use:
set arrow from 3, graph 0 to 3, graph 1 nohead

Upvotes: 57

To elaborate on previous answers about the "every x units" part, here is what I came up with:

# Draw 5 vertical lines
n = 5

# ... evenly spaced between x0 and x1
x0 = 1.0
x1 = 2.0
dx = (x1-x0)/(n-1.0)

# ... each line going from y0 to y1
y0 = 0
y1 = 10

do for [i = 0:n-1] {
    x = x0 + i*dx
    set arrow from x,y0 to x,y1 nohead linecolor "blue" # add other styling options if needed
}

Upvotes: 1

littlemind
littlemind

Reputation: 256

You can use the grid feature for the second unused axis x2, which is the most natural way of drawing a set of regular spaced lines.

set grid x2tics
set x2tics 10 format "" scale 0

In general, the grid is drawn at the same position as the tics on the axis. In case the position of the lines does not correspond to the tics position, gnuplot provides an additional set of tics, called x2tics. format "" and scale 0 hides the x2tics so you only see the grid lines.

You can style the lines as usual with linewith, linecolor.

Upvotes: 11

alternatively you can also do this:

p '< echo "x y"' w impulse

x and y are the coordinates of the point to which you draw a vertical bar

Upvotes: 17

Throwback1986
Throwback1986

Reputation: 6005

Here is a snippet from my perl script to do this:

print OUTPUT "set arrow from $x1,$y1 to $x1,$y2 nohead lc rgb \'red\'\n";

As you might guess from above, it's actually drawn as a "headless" arrow.

Upvotes: 49

Related Questions