Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot a function of an imported data in gnuplot?

Tags:

gnuplot

If I have a file of several data points. How can I plot a function of them? For example, suppose I have a file of to columns x and y and I want to plot sin(y) as a function of 1/x.

like image 807
Yotam Avatar asked Aug 04 '11 09:08

Yotam


People also ask

How use gnuplot to plot data from a file?

To plot functions simply type: plot [function] at the gnuplot> prompt. Discrete data contained in a file can be displayed by specifying the name of the data file (enclosed in quotes) on the plot or splot command line. Data files should have the data arranged in columns of numbers.

Can gnuplot read Excel file?

GnuPlot scripts are stored in Excel along with the generated graphs and can be instantly edited and regenerated without leaving the Excel environment. Data can be read from Excel sheets by a cell range ("A1:C400") or using an Excel named range.

How the plot generated by gnuplot may be saved in a file?

There are two ways to save your work in gnuplot: you can save the gnuplot commands used to generate a plot, so that you can regenerate the plot at a later time. Or you can export the graph to a file in a standard graphics file format, so that you can print it or include it in web pages, documents, or presentations.

What is gnuplot Splot?

splot is the command for drawing 3-d plots (well, actually projections on a 2-d surface, but you knew that). It can create a plot from functions or a data file in a manner very similar to the plot command. See plot (p. ) for features common to the plot (p. ) command; only differences are discussed in detail here.

How to make a data plot using gnuplot?

Now everything is ready to make the data plot: by typing only gnuplot will produce a graph in your output destination. The default settings will use the first two columns of your data file, respectively x and y. To specify the columns to be plotted use the using specifier which means "plot the file using column 2 as X and column 4 as Y".

How does the plot of data work?

It works basically like the plotting of functions. But in this case we need a data file and some commands to manipulate the data. First, we will start with the basic plotting of simple data and thereafter look at the plotting of data with errors.

How to plot power values in gnuplot using mw?

The power values are stored in Watt in the data file, but only has values lower than 1. That’s why we want to use mW as unit. Therefore we set the format option to tell gnuplot to use “mantissa to base of current logscale”, see gnuplot’s documentation. Then in the plot command using tells gnuplot which columns from the data file it should use.

How to plot Z-columns in gnuplot?

In the case your data set is a tridimensional file just use splot ad add the z-column There are also different style (see gnuplot documentation or Selecting a plotting style for further infos) for plotting points. As said before, the default style is point which will plot the same as if you do not type with point.


1 Answers

Try this:

plot "-" u (1/$1):(sin($2)) w l
    2.00000    0.16104
    3.00000    0.15604
    4.00000    0.40055
    5.00000    0.09972
    e

Or when not using data files make use of the parametric mode, which is described here

EDIT

With this data file Data.csv:

 0.00000    0.33371
 1.00000    0.13034
 2.00000    0.16104
 3.00000    0.15604
 4.00000    0.40055
 5.00000    0.09972
 6.00000    0.25204
 7.00000   -0.34172
 8.00000   -0.04733
 9.00000   -0.27211
10.00000    0.10229
11.00000   -0.30608
12.00000    0.11006
13.00000   -0.44390
14.00000   -0.16963
15.00000    0.03208
16.00000    0.32431
17.00000    0.15424
18.00000    0.16468
19.00000    0.24410
20.00000    0.34961

I can run this script:

f(x) = kappa*x**2

fit f(x) "Data.csv" u (log($1)):(sin($2)) via kappa
plot "Data.csv" u 1:(sin($2)), f(x) w l

Which gives me this plot:

Plot of the above script and data file

Granted, the fitting does not make any sense at all^^.

Are you maybe missing some brackets in your fit?!

like image 180
Woltan Avatar answered Sep 21 '22 14:09

Woltan