ilikecake1
ilikecake1

Reputation: 41

How to plot a specific graph in gnuplot

I have a file that I need to plot in a graph that looks similar to this: gnuplot sample graph

Here is my file that I am trying to plot:

441.81   823.36   192765   3044.68   4242.61
X        2609.3   4901.96  8306.6    12058.18
1632.27  4098.15  9299.14  16295.19  24665.59

I can do a simple plot, but changing the line types and using a file is what I am having trouble with. I'm not sure how to get the data from the file into the plot and make it formatted like the sample image.

Upvotes: 0

Views: 94

Answers (1)

F. Knorr
F. Knorr

Reputation: 3055

You probably should dig a little deeper into gnuplot. A good start is this article on plotting data.

Anyway, let's define three distinct line styles:

set style line 1 lc 'blue' lt 1 lw 2 pt 6 ps 1.5  
set style line 2 lc 'red' lt 1 lw 2 pt 6 ps 1.5  
set style line 3 lc 'green' lt 1 lw 2 pt 6 ps 1.5  

Then, we can call the plot function on our inputFile:

plot 'inptFile' u 1:2 w lp ls 1, '' u 1:3 w lp ls 2, '' u 1:4 w lp ls 3

(u 1:2 stands for using 1:2 and means that we use the value in the first column as x-coordinate and the value in the second column as the y-coordinate. )

Note that our inputFile looks like this (i.e., each line contains a point's x and y-coordinate):

-1 2 3 4
0 1 2 4
1 2 4 16
2 3 16 8

Output: enter image description here

Upvotes: 1

Related Questions