How to plot data without data files in Gnuplot

Last updated on August 9, 2020 by Dan Nanni

When you write a Gnuplot script for plotting data, the script typically loads data from separate data file(s). This means that you need to maintain Gnuplot scripts and raw data files separately. It will be nice if a Gnuplot script is able to plot data without relying on external data files.

If you want to plot data without data files with Gnuplot, you can use a special filename named -, which allows you to include raw data inline within scripts. For example, you can include raw data in your Gnuplot script as follows.

plot '-' using 1:2 title "My Plot" with lp
        1 30
        2 40
        3 35
        4 60
        5 50
EOF

If you want to draw multiple plots, each of which is based on a different set of raw data, you can specify as many instances of - as you want in your Gnuplot script.

plot '-' using 1:2 title "My Plot 1" with lp, 
     '-' using 1:2 title "My Plot 2" with lp
        1 30
        2 40
        3 35
        4 60
        5 50
EOF
        1 20
        2 40
        3 40
        4 50
        5 60
EOF

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal (Credit Card) or Bitcoin (1M161JGAkz3oaHNvTiPFjNYkeABox8rb4g).

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean