How to plot data without data files in Gnuplot

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

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.
Your name can also be listed here. Write for us as a freelancer.

Leave a comment

Your email address will not be published. Required fields are marked *

Current ye@r *