Create scientific plots using gnuplot

February 21st, 2014 | 5 Comments

For the measurement of distances T-shaped arrows are often used to highlight the length. In gnuplot there is an easy way to achieve this.

Diffraction on a slit

Fig. 1 Diffraction of light for a slit with the length d. (code to produce this figure)

Have a look at Fig. 1 which tries to explain the diffraction phenomenon of a slit with the length d. At a distance a the diffraction pattern is drawn. The different distances, the distance between the first minima of the diffraction pattern, and the wave length are indicated by T-shaped arrows. This kind of arrays can be achieved in gnuplot with the following code.

Theads = 'heads size 0.5,90 front ls 201'
set arrow from -24,-2 to -24, 2       @Theads
set arrow from -22, 2 to -21.44,1.92  @Theads
set arrow from 1.5,-pi to 1.5,pi      @Theads
set arrow from -22,2.5*pi to 0,2.5*pi @Theads

Here, 90 is the relevant entry after size as it describes the opening angle of the arrow head.
In addition, an open circle is drawn to indicate the angle θ. This is achieved by specifying the opening angle for the circle object.

set object circle at -22,0 size 6 arc [-8:0]


  1. Angelo Puglisi says:

    I tried your code and I got “invalid character @”, so I found (in another post of yours) that “set macros” is needed. I think you forgot it because you have it in your configuration :)

    I’m leaving this comment to ease the life of anybody else that could have the same issue.

    My compliments for this website!

  2. hagen says:

    Hi Angelo, that is a very good hint. I thought the reset command at the beginning would overwrite the configuration settings, but it doesn’t and I have a set macros line in my config file.

    I added the missing code to the file and removed the line from my config, thank you.

  3. Christoph says:

    Instead of using macros you can also use set style arrow:

    set style arrow 1 heads size 0.5,90 front ls 201
    set arrow from -24,-2 to -24, 2 arrowstyle 1
  4. hagen says:

    Thanks Christoph, that is even nicer. I added an updated version of the code using the suggested arrow styles.

  5. frank says:


    You saved me some time in figuring it out.