Difference between revisions of "Gnuplot/C2/Error-bars-and-data-fitting/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 1: Line 1:
  
{|border=1
+
{| border=1
 +
|| '''Visual Cue'''
 +
|| '''Narration'''
  
 
|-
 
|-
|| Visual Cue
+
|| '''Slide Number 1'''
|| Narration
+
 
+
|-
+
||'''Slide Number 1'''
+
 
'''Title Slide '''
 
'''Title Slide '''
'''Data fitting and error bars'''
+
|| Welcome to the tutorial on  
||Welcome to the tutorial on '''Data fitting and error bars'''
+
'''Error bars and data fitting '''in gnuplot.
  
 
|-
 
|-
||'''Slide Number 2'''
+
|| '''Slide Number 2'''
 
'''Learning Objectives'''
 
'''Learning Objectives'''
||In this tutorial, we will learn,
+
|| In this tutorial, we will,
*Learn to add error bars in a graph
+
* Learn to add error bars in a plot
*Learn data fitting
+
* Learn about data fitting
*Fit a given dataset to an equation  
+
* Write an equation to fit the data
*Run non-linear regression and generate fitting parameters
+
* Make initial guess for value of the coefficients
 +
* Fit the dataset to the equation  
 +
* Draw an arrow object in the graph
  
 
|-
 
|-
||'''Slide Number 3'''
+
|| '''Slide Number 3'''
 
'''System and Software Requirement'''
 
'''System and Software Requirement'''
||*Debian Linux 9 .3
+
|| To record this tutorial, I am using,
*Gedit 3.22.0 and
+
* '''Ubuntu Linux''' 16.04
*gnuplot 5.2.5 installed
+
* '''Gnuplot''' 5.2.6 and  
 +
* '''Gedit''' 3.18
  
 
|-
 
|-
||'''Slide Number 4'''
+
|| '''Slide Number 4'''
 
'''Pre-requisites'''
 
'''Pre-requisites'''
||To follow this tutorial, learner’s must be familiar with,
+
[https://spoken-tutorials.org https://spoken-tutorials.org]
*Basic computer and internet skills
+
|| To follow this tutorial, * Learner must be familiar with the basics of '''gnuplot'''.
*Concept of graphing and
+
* For the prerequisite tutorials, please visit this site.
*College level Mathematics skills
+
  
 
|-
 
|-
|| Go to '''Desktop'''.
+
|| '''Slide Number 5'''
||First, we will first learn to incorporate error bars in a graph.
+
'''Code files'''
First, Go to '''Desktop'''.
+
|| The input file used in this tutorial is provided in the '''code file''' link.
I have a, x y yerror type data, in a text file.  
+
Please download and extract the files.
  
 
|-
 
|-
|| Double click to open the file.
+
|| Go to '''Desktop'''.
||It is saved in '''Desktop''' directory for me.  
+
|| Go to '''Desktop'''.
Double click on the file icon to open it in a text editor.
+
I have a, '''x,''' '''y,''' '''y'''-error type data, in a text file.  
The file opens in gedit for me.
+
This file is provided to you with the tutorial.
+
  
 
|-
 
|-
|| Hover mouse over columns
+
|| Hover mouse over '''x''', '''y''' and '''dy''' columns on the screen for the file.
|| The first column is '''x''' data.
+
|| The first column is x data.
Second column is '''y''' data.
+
The second column is '''y''' data.  
The third column is '''y''' data error bar in measurement.
+
The third column is error in the '''y''' data.
  
 
|-
 
|-
|| Close '''gedit'''
+
|| Close '''gedit'''.
|| Close '''gedit''' by clicking on the x-sign.
+
Press '''Ctrl+Alt+T'''.
 +
|| Close the file.
 +
Open a '''terminal'''.
  
 
|-
 
|-
||Press '''ctrl alt t'''
+
|| Enter the command '''cd Desktop '''.
'''cd ~/Desktop'''
+
Enter the command '''gnuplot'''.
|| Press '''ctrl alt t''' keys together to open a '''terminal'''.
+
|| Change the directory to '''Desktop''' and open '''gnuplot'''.
Change directory to '''Desktop''' as seen on the screen.
+
  
 
|-
 
|-
||'''gnuplot'''
+
|| Press '''Ctrl+L'''.
|| Open '''gnuplot'''.
+
|| I will clear the screen.
Type '''gnuplot''' and '''enter'''
+
  
 
|-
 
|-
|| Show qt on screen.
+
|| Cursor on the '''terminal'''.
||'''Set''' '''terminal''' as necessary.  
+
|| Let's plot the data to see the trend.  
For me it is already in '''qt'''.
+
  
 
|-
 
|-
|| '''Ctrl-l'''
+
|| Enter the command '''plot 'error-bar.txt' using 1:2:3 with yerrorbars''' .
|| I will clear screen with command control l.
+
|| Enter the '''plot''' command as seen on the screen.
This takes terminal prompt to top of the screen for clarity in video.
+
  
 
|-
 
|-
||  
+
|| Hover mouse over ''':3''' .
|| First, let's plot the data to see the trend and for visual inspection.
+
|| The command, colon 3 with y error bars adds the error to the plot.
  
 
|-
 
|-
|| '''plot 'error-bar.txt' using 1:2:3 with yerrorbars'''
+
|| Hover mouse over '''yerrorbars'''.
|| Enter the plot command as seen on the screen.
+
|| If error limits are on the '''x''' data, we have to use, '''x''' errorbars term for plotting.
 +
The graphic window opens.
  
 
|-
 
|-
||  
+
|| Hover mouse over decay curve.
|| If error limits are on the x data, we can use, x error bars term for plotting.
+
|| Let's fit this graph to an equation.  
The graphic window opens.
+
  
 
|-
 
|-
||  
+
|| Cursor on the graph.
|| The colon 3 with y error bars in the plot command adds the error to the plot.
+
|| Here, the data points are likely to follow an exponential decay.
  
 
|-
 
|-
|| Hover mouse over decay curve.
+
|| Hover mouse on the graph.
|| Next, let's fit this graph to an equation.  
+
|| The points may deviate from an accurate exponential decay.
 +
This could be due to measurement errors.
  
 
|-
 
|-
||  
+
|| Point mouse next to data.
|| This data likely represent an exponential decay.
+
|| We will fit the given data points to an '''exponential decay''' function.
  
 
|-
 
|-
||  
+
|| Cursor on the screen.
|| The points may be off the ideal curve due to measurement errors.
+
|| Let's see a few steps involved in fitting data points with an equation.
  
 
|-
 
|-
 +
|| '''Slide Number 6'''
 +
'''Steps for Fitting Data'''
 
||  
 
||  
|| We will fit the given data points to an exponential decay function.
+
* Define an equation to represent the data.
 +
* Make initial guess values for the coefficients in the equation.
 +
* Optimal values for the coefficients is found by an iterative process.
 +
 
  
 
|-
 
|-
 +
|| '''Slide Number 7'''
 +
 +
'''Steps for Fitting Data'''
 
||  
 
||  
|| Let's see a few steps involved in fitting data points to an equation.
+
* Check for goodness of the fit
 +
* A good fitting is measured by a low value of chi square
  
|-
+
 
||'''Slide Number 5'''
+
 
'''Steps in data fitting'''
+
and * Display the fitted data with the starting dataset
|| First, define a function to represent the data
+
Make initial guess values for constants
+
A good fitting, measured by '''chi square''' value
+
Find the 'optimal' value of the constants in the function
+
and Display the fitted data
+
  
 
|-
 
|-
|| '''f(x) = a * exp(-k*x)'''
+
|| Type, '''f(x) = a * exp(-k*x)'''  
||First, let's define the function.
+
and press '''Enter'''.
Type '''f''' of '''x''' is equal to a times '''e''' to the power minus '''k x'''
+
|| First, let's define the function.
Use the syntax as seen on the screen
+
In the '''gnuplot''' prompt, type f of x is equal to a times e to the power minus k x.
  
 
|-
 
|-
 
|| Go to graphical window.
 
|| Go to graphical window.
||Let's make an educated initial guess for the initial guess values of a and k
+
|| Make an educated initial guess for the values of '''a''' and '''k'''.
Go to graphical window.
+
Go to the graphical window.
  
 
|-
 
|-
||  
+
|| Hover mouse near top of y axis.
|| From the graph, I will place the initial value of a at one lakh fitfty thousand
+
|| From the graph, I will place the initial value of '''a''' at '''1,50,000'''.
  
 
|-
 
|-
||  
+
|| Hover mouse to show ½ decay.
|| For an exponential decay, I will place the initial guess of k around 0.5
+
|| For an exponential decay, I will place the initial guess of '''k''' around '''0.5''' .
  
 
|-
 
|-
||  
+
|| Close the graphical window.
|| Close the graphical window and go to gnuplot terminal prompt.
+
|| Close the graphical window and go to the '''gnuplot terminal''' prompt.
  
 
|-
 
|-
||'''a=150000 '''
+
|| Enter the commands,
 +
'''a=150000 '''
 
'''k=0.5'''
 
'''k=0.5'''
||Enter commands to set the values of a and k
+
|| Enter commands to set initial guess values.
Enter a equal to fifteen hundred thousand
+
Set '''a''' to 150 thousand and '''k''' to 0.5 .
Enter k equal to zero point five
+
  
 
|-
 
|-
|| '''fit f(x) “error-bar.txt” using 1:2:3 via a,k'''
+
|| Type, '''fit f(x) ‘xydy.txt’ using 1:2:3 via a,k'''
||To fit the data use command as seen on the screen.
+
and press '''Enter'''.
Fit space f of x space in double quotes error hyphen bar dot txt.  
+
|| To fit the data type the command,
Then Space using space 1 colon 2 colon 3 via a comma k
+
'''fit f of x''' in single quotes the file name.
 +
Here it is '''error dash bar dot txt'''.  
 +
Then '''using 1 colon 2 colon 3''' via a comma k .
 +
Here '''a''' and '''k''' are the '''coefficients'''.
  
 
|-
 
|-
||  
+
|| Hover mouse over ''':3''' .
|| If column 3 is not mentioned, the y axis uncertainties is not considered for data fitting.
+
|| We could leave out the colon 3 in the command.
 +
Then, errors in the '''y''' data are not considered during the data fitting  
 +
process.
  
 
|-
 
|-
||  
+
|| Press '''Enter'''.
|| The software does the fitting and gives output values.
+
Data fitting is seen on the screen.
 +
|| Press '''Enter''' to run the data fitting algorithm.
 +
The coefficients in the equation are optimized by an iterative process.
 +
The output is generated on the screen.
  
 
|-
 
|-
||  
+
|| Scroll up.
 
|| Let's scroll up the screen.
 
|| Let's scroll up the screen.
  
 
|-
 
|-
 
||  
 
||  
|| I see an error , warning message on top
+
|| I see an error warning message on the top.
  
 
|-
 
|-
||  
+
|| Hover mouse over the '''chi square''' table.
|| Notice a table with chi square and new values of a and k after each iteration.
+
|| Notice a table with '''chi square''' and new values of '''a''' and '''k''' after each iteration.
  
 
|-
 
|-
||  
+
|| Incorporate the number of iterations.
||Program reports, the fitting process converged after a few iterations.
+
|| The program reports that, the fitting process converged after 10 iterations.
It is 8 iteractions.
+
  
 
|-
 
|-
||  
+
|| Hover mouse over '''final sum of square of residuals'''.
||Many fitting parameters are reported in the output.
+
|| Many fitting parameters are reported in the output.
 
Program reports, final sum of square of residuals.
 
Program reports, final sum of square of residuals.
  
 
|-
 
|-
||  
+
|| Hover mouse over iteration value.
||Notice, relative change in values after the last iteration.
+
|| Notice, relative change in values after the last iteration.
The number is very small
+
 
 +
 
 +
The number is very small.
  
 
|-
 
|-
||  
+
|| Hover mouse over '''Degrees of freedom'''.
|| Degrees of freedom is 9
+
|| '''Degrees of freedom''' is 9.
  
 
|-
 
|-
||  
+
|| Hover mouse over '''RMS'''.
|| The root mean square or RMS is around 0.17  
+
|| '''RMS''' of residuals is around 0.17.
  
 
|-
 
|-
||  
+
|| Show '''a''' and '''k''' values on the screen.
|| Updated values of a and k and their error in estimation is also shown.
+
|| Updated values of '''a''' and '''k''' and their error in estimation is also shown.
  
 
|-
 
|-
||  
+
|| Hover mouse over the '''correlation matrix'''.
|| The correlation matrix of variables is at the end of the output.
+
|| The '''correlation matrix''' of variables is at the end of the output.
  
 
|-
 
|-
||  
+
|| Cursor on the '''terminal'''.
 
|| Now we have a function that fits the given data points.
 
|| Now we have a function that fits the given data points.
 +
Let's plot the data points and function together.
  
 
|-
 
|-
||  
+
|| Press '''Ctrl+L''' .
|| Let's plot the data points and function together.
+
|| I will clear the screen.
  
 
|-
 
|-
||  
+
|| Enter the command, '''plot f(x) lw 2 title 'fitted data', "xydy.txt" using 1:2:3 with yerrorbars pt 7 ps 1.5 notitle''' .
||Then, we can see, how well the equation fit the given points.
+
|| Enter the command as seen on the screen, to plot both data together.
I will clear the screen with command control l for clarity in video again.
+
We are plotting the fitted equation fit along with the initial data points.
  
 
|-
 
|-
|| '''plot f(x) lw 2 title 'fitted data', "error-bar-fitting.txt" using 1:2:3 with yerrorbars pt 7 ps 1.5 notitle'''
+
|| Hover mouse near the legend.
||Then, enter the plot command as seen on the screen.
+
|| The fitted data is represented by a line with a line.
 +
I am specifying the legend for '''f of x''' as '''fitted data'''.
 +
No legend title is added for the starting data set as no '''notitle''' is
 +
mentioned.
  
 
|-
 
|-
||  
+
|| Show the line on the graphics window.
||I will modify to change legend as '''fitted data''' for f of x.
+
Show symbol with error bar.
It is represented by a line with width 2.
+
|| Data points are represented by symbols with '''error bar''' and without a line style.
 +
I have specified a filled circle '''symbol''' and 1.5 for point size.
  
 
|-
 
|-
||  
+
|| Enter the command, '''set xrange [0.95:5.05]''' .
||I have specified no legend title for the starting data set.
+
|| Let's also set '''x axis''' limits with '''set xrange''' command as seen.
Data points are represented only by symbols with error bar and have no line.
+
 
I have specified a filled circle symbol and 1.5 for point size
+
|-
 +
|| Type '''replot''' and press '''Enter''' to see the graphics window.
 +
|| '''Replot''' to see the results.
 +
 
 +
|-
 +
|| Show this web site address screen shot.
 +
'''http://gnuplot.sourceforge.net/demo/fit.html'''
 +
|| Check the '''gnuplot''' website for example '''scripts''' on data fitting.
 +
 
 +
|-
 +
|| Cursor on the screen, around the (1.3,6000) region.
 +
|| Let’s draw an arrow object in the graph.
 +
I want to draw an arrow next to a point in the graph to highlight it.
 +
 
 +
|-
 +
|| Move the mouse on the screen to show the arrow placement around ('''1.63,77200 to 1.7, 62000''').
 +
|| In the graph, I want to add an arrow between these two points.
 +
 
 +
|-
 +
|| Highlight in video, the co-ordinates seen on the graph window.
 +
('''1.63,77200 to 1.7, 62000''').
 +
|| I will note down the coordinates as seen in the graphics window.
 +
 
 +
|-
 +
|| Go to the '''terminal'''.
 +
|| Go to the '''terminal'''.
 +
 
 +
|-
 +
|| Type, '''set arrow 1 from 1.63,77200 to 1.7, 62000''' and press '''Enter'''.
 +
|| Enter the commands as seen on the screen.
 +
Here, '''one '''is the name I have given for the arrow object.
 +
 
 +
|-
 +
|| Type '''replot''' and press '''Enter'''.
 +
|| '''Replot''' to see the updated result.
 +
 
 +
|-
 +
|| Cursor on the graphics window.
 +
|| I will also add a second arrow in another direction.
 +
 
 +
|-
 +
|| Type,
 +
'''set arrow 2 from 1.63,77200 to 1.4, 62000''' and press '''Enter'''.
 +
|| Go to the '''terminal''' and enter the command as seen on the screen.
 +
I will name this arrow as '''second'''.
 +
 
 +
|-
 +
|| Type '''replot''' and press '''Enter'''.
 +
|| '''Replot''' to see the updated result.
 +
 
 +
|-
 +
|| Cursor on the graphics window.
 +
|| Now we see two arrows in the graphics window.
 +
To remove the object, we have to '''unset''' the object.
 +
 
 +
|-
 +
|| Type '''unset arrow first''' and press '''Enter'''.
 +
|| Go to the '''terminal'''.
 +
Enter the command, '''unset arrow first''' to remove the first arrow.
 +
 
 +
|-
 +
|| Type '''replot''' and press '''Enter'''.
 +
|| '''Replot''' to see the updated result.
  
 
|-
 
|-
|| '''set xrange [0.95:5.05]'''
+
|| Cursor on the graphics window.
||Please pause video as necessary to practice.
+
|| The arrow that was named '''first''' is now removed from the graphics window,
Let's also set x axis limits with set xrange command as seen in the video.
+
  
 
|-
 
|-
|| '''replot'''
+
|| Close the graphics window.
|| Replot to see the results.
+
Type '''quit''' and press '''Enter'''.
 +
|| Close the graphics window and '''quit gnuplot'''.
  
 
|-
 
|-
||'''Slide Number 6'''
+
|| '''Slide Number 8'''
 
'''Summary'''
 
'''Summary'''
|| Now let’s summarize.
+
|| To summarize, in this tutorial, we learned to
In this tutorial, we learned to
+
* Incorporated error bars in a plot graph
* Display error bars in a graph
+
* Fit a given set of data points to an equation
* Fit a given set of data points to an equation<br/>and
+
* Plotted the fitted curve along with parent data
* Display fitted curve along with parent data
+
* Added and removed an arrow object
  
 +
|-
 +
|| '''Slide Number 9'''
 +
'''Assignment 1'''
 +
|| For the assignment activity, please do the following.
 +
* For the data file '''assignment.txt''', make an xy graph with ''xyerrorbars'' in the graph.
 +
* This file is available in the Code files link.
  
 
|-
 
|-
||'''Slide Number 7'''
+
|| '''Slide Number 9'''
'''Assignment'''
+
'''Assignment 2'''
||For assignment activity, please do the following.
+
||  
For data file assignment.txt, plot x and y error bars in graph.
+
* Fit the data to a double exponential decay curve with ''yerrorbars''.
The file is provided to you along with the tutorial.
+
* Plot the fitted data
Fit the data to a double exponential decay curve.
+
* Draw an arrow object in the graph at the position of your choice.
  
 
|-
 
|-
||'''Slide Number 8'''
+
|| '''Slide Number 10'''
 
'''Spoken Tutorial Project'''
 
'''Spoken Tutorial Project'''
||This video summarises the Spoken Tutorial Project  
+
|| This video summarises the '''Spoken Tutorial''' Project .
 
Please download and watch it.
 
Please download and watch it.
  
 
|-
 
|-
||'''Slide Number 9'''
+
|| '''Slide Number 11'''
 
'''Spoken Tutorial workshops'''
 
'''Spoken Tutorial workshops'''
||We conduct workshops and give certificates.  
+
|| We conduct workshops and give certificates.  
Please write to us.
+
 
 +
For more details, please write to us.
  
 
|-
 
|-
||'''Slide Number 10'''
+
|| '''Slide Number 12'''
 +
 
 
'''Forum for specific questions:'''
 
'''Forum for specific questions:'''
 
|| Post your timed queries in the forum.
 
|| Post your timed queries in the forum.
  
 
|-
 
|-
||'''Slide Number 11'''
+
|| '''Slide Number 13'''
 
'''Acknowledgement'''
 
'''Acknowledgement'''
||Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
+
|| Spoken Tutorial Project is funded by '''MHRD''', '''Government of India'''.
  
 
|-
 
|-
 
||  
 
||  
|| Thank you for joining.  
+
|| This is Rani, from '''IIT''', '''Bombay'''.
 +
Thank you for joining.
  
 +
|-
 
|}
 
|}

Revision as of 13:40, 14 January 2020

Visual Cue Narration
Slide Number 1

Title Slide

Welcome to the tutorial on

Error bars and data fitting in gnuplot.

Slide Number 2

Learning Objectives

In this tutorial, we will,
  • Learn to add error bars in a plot
  • Learn about data fitting
  • Write an equation to fit the data
  • Make initial guess for value of the coefficients
  • Fit the dataset to the equation
  • Draw an arrow object in the graph
Slide Number 3

System and Software Requirement

To record this tutorial, I am using,
  • Ubuntu Linux 16.04
  • Gnuplot 5.2.6 and
  • Gedit 3.18
Slide Number 4

Pre-requisites https://spoken-tutorials.org

To follow this tutorial, * Learner must be familiar with the basics of gnuplot.
  • For the prerequisite tutorials, please visit this site.
Slide Number 5

Code files

The input file used in this tutorial is provided in the code file link.

Please download and extract the files.

Go to Desktop. Go to Desktop.

I have a, x, y, y-error type data, in a text file.

Hover mouse over x, y and dy columns on the screen for the file. The first column is x data.

The second column is y data. The third column is error in the y data.

Close gedit.

Press Ctrl+Alt+T.

Close the file.

Open a terminal.

Enter the command cd Desktop .

Enter the command gnuplot.

Change the directory to Desktop and open gnuplot.
Press Ctrl+L. I will clear the screen.
Cursor on the terminal. Let's plot the data to see the trend.
Enter the command plot 'error-bar.txt' using 1:2:3 with yerrorbars . Enter the plot command as seen on the screen.
Hover mouse over :3 . The command, colon 3 with y error bars adds the error to the plot.
Hover mouse over yerrorbars. If error limits are on the x data, we have to use, x errorbars term for plotting.

The graphic window opens.

Hover mouse over decay curve. Let's fit this graph to an equation.
Cursor on the graph. Here, the data points are likely to follow an exponential decay.
Hover mouse on the graph. The points may deviate from an accurate exponential decay.

This could be due to measurement errors.

Point mouse next to data. We will fit the given data points to an exponential decay function.
Cursor on the screen. Let's see a few steps involved in fitting data points with an equation.
Slide Number 6

Steps for Fitting Data

  • Define an equation to represent the data.
  • Make initial guess values for the coefficients in the equation.
  • Optimal values for the coefficients is found by an iterative process.


Slide Number 7

Steps for Fitting Data

  • Check for goodness of the fit
  • A good fitting is measured by a low value of chi square


and * Display the fitted data with the starting dataset

Type, f(x) = a * exp(-k*x)

and press Enter.

First, let's define the function.

In the gnuplot prompt, type f of x is equal to a times e to the power minus k x.

Go to graphical window. Make an educated initial guess for the values of a and k.

Go to the graphical window.

Hover mouse near top of y axis. From the graph, I will place the initial value of a at 1,50,000.
Hover mouse to show ½ decay. For an exponential decay, I will place the initial guess of k around 0.5 .
Close the graphical window. Close the graphical window and go to the gnuplot terminal prompt.
Enter the commands,

a=150000 k=0.5

Enter commands to set initial guess values.

Set a to 150 thousand and k to 0.5 .

Type, fit f(x) ‘xydy.txt’ using 1:2:3 via a,k

and press Enter.

To fit the data type the command,

fit f of x in single quotes the file name. Here it is error dash bar dot txt. Then using 1 colon 2 colon 3 via a comma k . Here a and k are the coefficients.

Hover mouse over :3 . We could leave out the colon 3 in the command.

Then, errors in the y data are not considered during the data fitting process.

Press Enter.

Data fitting is seen on the screen.

Press Enter to run the data fitting algorithm.

The coefficients in the equation are optimized by an iterative process. The output is generated on the screen.

Scroll up. Let's scroll up the screen.
I see an error warning message on the top.
Hover mouse over the chi square table. Notice a table with chi square and new values of a and k after each iteration.
Incorporate the number of iterations. The program reports that, the fitting process converged after 10 iterations.
Hover mouse over final sum of square of residuals. Many fitting parameters are reported in the output.

Program reports, final sum of square of residuals.

Hover mouse over iteration value. Notice, relative change in values after the last iteration.


The number is very small.

Hover mouse over Degrees of freedom. Degrees of freedom is 9.
Hover mouse over RMS. RMS of residuals is around 0.17.
Show a and k values on the screen. Updated values of a and k and their error in estimation is also shown.
Hover mouse over the correlation matrix. The correlation matrix of variables is at the end of the output.
Cursor on the terminal. Now we have a function that fits the given data points.

Let's plot the data points and function together.

Press Ctrl+L . I will clear the screen.
Enter the command, plot f(x) lw 2 title 'fitted data', "xydy.txt" using 1:2:3 with yerrorbars pt 7 ps 1.5 notitle . Enter the command as seen on the screen, to plot both data together.

We are plotting the fitted equation fit along with the initial data points.

Hover mouse near the legend. The fitted data is represented by a line with a line.

I am specifying the legend for f of x as fitted data. No legend title is added for the starting data set as no notitle is mentioned.

Show the line on the graphics window.

Show symbol with error bar.

Data points are represented by symbols with error bar and without a line style.

I have specified a filled circle symbol and 1.5 for point size.

Enter the command, set xrange [0.95:5.05] . Let's also set x axis limits with set xrange command as seen.
Type replot and press Enter to see the graphics window. Replot to see the results.
Show this web site address screen shot.

http://gnuplot.sourceforge.net/demo/fit.html

Check the gnuplot website for example scripts on data fitting.
Cursor on the screen, around the (1.3,6000) region. Let’s draw an arrow object in the graph.

I want to draw an arrow next to a point in the graph to highlight it.

Move the mouse on the screen to show the arrow placement around (1.63,77200 to 1.7, 62000). In the graph, I want to add an arrow between these two points.
Highlight in video, the co-ordinates seen on the graph window.

(1.63,77200 to 1.7, 62000).

I will note down the coordinates as seen in the graphics window.
Go to the terminal. Go to the terminal.
Type, set arrow 1 from 1.63,77200 to 1.7, 62000 and press Enter. Enter the commands as seen on the screen.

Here, one is the name I have given for the arrow object.

Type replot and press Enter. Replot to see the updated result.
Cursor on the graphics window. I will also add a second arrow in another direction.
Type,

set arrow 2 from 1.63,77200 to 1.4, 62000 and press Enter.

Go to the terminal and enter the command as seen on the screen.

I will name this arrow as second.

Type replot and press Enter. Replot to see the updated result.
Cursor on the graphics window. Now we see two arrows in the graphics window.

To remove the object, we have to unset the object.

Type unset arrow first and press Enter. Go to the terminal.

Enter the command, unset arrow first to remove the first arrow.

Type replot and press Enter. Replot to see the updated result.
Cursor on the graphics window. The arrow that was named first is now removed from the graphics window,
Close the graphics window.

Type quit and press Enter.

Close the graphics window and quit gnuplot.
Slide Number 8

Summary

To summarize, in this tutorial, we learned to
  • Incorporated error bars in a plot graph
  • Fit a given set of data points to an equation
  • Plotted the fitted curve along with parent data
  • Added and removed an arrow object
Slide Number 9

Assignment 1

For the assignment activity, please do the following.
  • For the data file assignment.txt, make an xy graph with xyerrorbars in the graph.
  • This file is available in the Code files link.
Slide Number 9

Assignment 2

  • Fit the data to a double exponential decay curve with yerrorbars.
  • Plot the fitted data
  • Draw an arrow object in the graph at the position of your choice.
Slide Number 10

Spoken Tutorial Project

This video summarises the Spoken Tutorial Project .

Please download and watch it.

Slide Number 11

Spoken Tutorial workshops

We conduct workshops and give certificates.

For more details, please write to us.

Slide Number 12

Forum for specific questions:

Post your timed queries in the forum.
Slide Number 13

Acknowledgement

Spoken Tutorial Project is funded by MHRD, Government of India.
This is Rani, from IIT, Bombay.

Thank you for joining.

Contributors and Content Editors

Madhurig, Ranipv076, Snehalathak