Gnuplotting

Create scientific plots using gnuplot

October 6th, 2010 | 12 Comments

If we want to plot a single point, we can do this by creating a data file, containing only one line:

# x   y
1   2

But there exist an easier method without any additional data file. In Fig. 1 three points with different symbols are plotted.

Three points

Fig. 1 Plot of three single points (code to produce this figure)

To achieve this we just use the following command:

plot '-' w p ls 1, '-' w p ls 2, '-' w p ls 3
1 2
e
2 1
e
3 1.5
e

We use the possibility to tell Gnuplot with the '-' input to read from standard input. Here we tell Gnuplot to do this three times. After the plot command the data is entered. Every single data entry have to ended with the e line.
In order to have different symbols for the points we set them before:

set style line 1 lc rgb 'black' pt 5   # square
set style line 2 lc rgb 'black' pt 7   # circle
set style line 3 lc rgb 'black' pt 9   # triangle

Note: if we want to use the replot command then the above code will not work probably. But the same can be achieved by using:

plot "<echo '1 2'"   with points ls 1, \
     "<echo '2 1'"   with points ls 2, \
     "<echo '3 1.5'" with points ls 3

12 Comments

  1. Morri says:

    This was really helpful.

    When I plot using the open symbols like pt 4 or pt 6 they always have a little dot in the center. Is there anyway to avoid this?

    Thanks,
    Morri

  2. hagen says:

    Yes, I know the annoying little dot at the center.
    I’m using mostly postscript (eps) files. After plotting I open them in Inkscape and remove the little dot.
    For png or other terminals I have no solution at the moment.

  3. […] es una traducción a Español de un post en inglés. Me pareció interesante proporcionar esta información traducida al español. Espero que sea de […]

  4. Johne572 says:

    I really like your blog.. very nice colors &amp theme. Did you make this website yourself or did you hire someone to do it for you? Plz respond as I’m looking to construct my own blog and would like to know where u got this from. thank you fegbdefffeae

  5. hagen says:

    Hi Johne,
    I made it by myself using Bootstrap as a basis which is a very good start if you have some HTML/CSS knowledge. The color theme is inspired by Tarski which I used for an early version of the blog.

  6. Iulian says:

    Thank you very very very much! That article helped me a lot!

  7. Tim says:

    Makes me think

    ax=10
    ay=-1
    plot "<echo 1 1" using (ax):(ay)
    

    This is a bit of an abuse, but useful for calculated locations.

  8. hagen says:

    That’s true and it can be formulated even shorter using the special filename

    ax=10
    ay=-1
    plot '+' using (ax):(ay)
    
  9. lev says:
    plot "echo ax ay" w p pt n
    
  10. lev says:

    sorry,

    plot “< echo ax ay” w p pt n
    

    ax, ay do not need to be preset, you may write your numbers straight after "< echo"

  11. Joe says:

    How does this work with variables? i just get
    Bad data on line 1 of file < echo ax ay

    But it does seem to work with explicit numbers.

  12. hagen says:

    Hi Joe.

    The easiest way is the one stated above

    ax=10
    ay=-1
    plot '+' using (ax):(ay)
    

    Otherwise you can do

    ax=10
    ay=-1
    plot "<echo ".ax." ".ay
    

Leave a Reply