plot graph in gnuplot from csv and data file | knowledge of physics

 If you are using LINUX based OS, for example Ubuntu, you must be familiar with plotting data in gnuplot saved in a file with .dat extension. It is very simple technique. 

To plot data in .dat format, you simply go to gnuplot and run following command,


gnuplot> plot 'file_name.dat' using 1:2 


This command gives you simple plot of your data saved in  file_name.dat. You can further modify this plot by adding title, axes names, legends and colors of plot and width etc. Here 1:2 means first column of data is along x-axis and second column along y-axis.

But what about if you have data in a file of  .csv format ?

Let's discuss.

CSV means coma separated variables. This means each column of the data in the .csv file is separated by coma (,), and gnuplot does not accept this format directly just as you do for the .dat file. 

For gnuplot to read data from .csv file, you should tell it that data you are applying are in coma separated format. So, write code as below:


gnuplot > unset logscale x

gnuplot> set  datafile separator "," 

gnuplot> plot "book1.csv" u 1:2


Here first line says gnuplot to set that x axis data are not in log scale. It is optional. 

second line tells gnuplot that data file is in csv format.

Third line tells gnuplot to plot the graph stored in data file named book1.csv by using column 1 in x-axis and column 2 in y-axis.

Code provided above plots only a simple graph. You can set title, xlabel, ylabel, legends etc. by watching video provided in the following link 👇.

Among three lines, second line code is optional. 


Watch Video


watch  full information of creating .csv file with excel and plotting graph from this file in gnuplot.


For more details, watch the video 







👍 To learn to create GIF animation in gnuplot: Click Here



👉 Learn to plot graphs from data in .csv and .dat format: Click Here



For more updates visit the home page.

Comments

These posts may also be useful for you

top 3 websites for downloading research papers for free

projectile motion in fortran | relation of angle of projection and horizontal range

NEB physics exam numerical problems with solutions for grade 12 students

how to plot 3D and parametric graphs in gnuplot | three dimensional plot in gnuplot software

how to create GIF animation in gnuplot | animation using gnuplot software

NEB board exam maths solved problems with proper solutions - available for free | short answered mathematics problems solved group A

NEB grade 11 and 12 maths exam MCQ solved problems | NEB mathematics MCQ solved problems