Difference between revisions of "Gnuplot/C2/Plotting-datasets-from-file/English"
Snehalathak (Talk | contribs) |
|||
(7 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{|border=1 | {|border=1 | ||
− | || Visual Cue | + | ||'''Visual Cue''' |
− | || Narration | + | ||'''Narration''' |
|- | |- | ||
|| '''Slide Number 1''' | || '''Slide Number 1''' | ||
'''Title Slide ''' | '''Title Slide ''' | ||
− | + | || Welcome to the tutorial on '''Plotting Dataset from a File''' in '''gnuplot'''. | |
− | || Welcome to the tutorial on '''Plotting | + | |
|- | |- | ||
Line 13: | Line 12: | ||
'''Learning Objectives''' | '''Learning Objectives''' | ||
|| In this tutorial we will learn to, | || In this tutorial we will learn to, | ||
− | * Plot | + | * Plot xy graph from a dataset in a file |
− | + | * Write the legend title | |
− | * Write legend | + | |
− | + | ||
* Set symbol style and size | * Set symbol style and size | ||
− | * Change axis format | + | * Add two datasets in the plot |
− | + | * Change axis format to log scale | |
|- | |- | ||
|| '''Slide Number 3''' | || '''Slide Number 3''' | ||
+ | '''Learning Objectives''' | ||
+ | || | ||
+ | * Change the line color | ||
+ | * Format the label style to scientific notation | ||
+ | * Format the border line and | ||
+ | * Add time stamp | ||
+ | |||
+ | |- | ||
+ | || '''Slide Number 4''' | ||
'''System and Software Requirement''' | '''System and Software Requirement''' | ||
|| To record this tutorial, I am using | || To record this tutorial, I am using | ||
− | * Debian Linux 9 | + | * '''Debian Linux''' 9.3 |
− | * | + | * '''gnuplot 5.2.6''' and |
− | * | + | * '''Gedit''' 3.22.0 |
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 5''' |
'''Pre-requisites''' | '''Pre-requisites''' | ||
− | || To follow this tutorial, | + | https://www.spoken-tutorial.org |
− | + | || To follow this tutorial, | |
− | + | * Learner must be familiar with, High school Mathematics. | |
− | + | * For pre-requisite '''gnuplot''' tutorials, please visit this site. | |
− | + | ||
|- | |- | ||
− | || Go to '''Desktop''' | + | || Go to Desktop and cursor on '''Desktop '''. |
− | || Go to '''Desktop''' | + | || Go to '''Desktop''' . |
− | We will plot a graph | + | We will plot a graph using the data in a '''text''' file, named '''data.txt'''. |
− | The file is provided | + | |
+ | The file is provided in the '''codefiles''' link of this tutorial. | ||
|- | |- | ||
− | || Show data.txt icon in Desktop directory. | + | || Show '''data.txt''' icon in '''Desktop''' directory. |
− | || | + | || I have downloaded and saved the file on '''Desktop'''. |
|- | |- | ||
− | || Double click on the icon | + | || Double click on the icon. |
|| Double click on the file icon to open and view the file. | || Double click on the file icon to open and view the file. | ||
− | + | The file opens in '''gedit''' text editor for me. | |
|- | |- | ||
− | || Hover | + | || Hover mouse and show on screen. |
− | || | + | || The data has three columns. |
− | The first row consists of | + | The first row consists of headings and starts with a hash. |
|- | |- | ||
− | || | + | || Point to columns. |
− | || | + | || The first column contains x axis data, 2<sup>nd</sup> and 3<sup>rd</sup> columns are two sets of y data. |
− | + | ||
|- | |- | ||
− | || Click on x sign | + | || Click on the '''x''' sign. |
− | || Close the file by | + | || Close the data file by clicking on the ''''x'''' button. |
|- | |- | ||
− | || ''' | + | || Press '''Ctrl+Alt+T '''. |
− | || Press | + | || Press '''Control''', '''Alt''' & '''T''' keys together on keyboard to open the terminal. |
|- | |- | ||
|| | || | ||
− | || | + | || The terminal opens. |
|- | |- | ||
− | || '''cd Desktop''' | + | || Type '''cd Desktop '''and press''' Enter'''. |
− | || Change directory to '''Desktop''' directory | + | || Change directory to '''Desktop''' directory as seen on the screen. |
|- | |- | ||
− | || '''gnuplot''' | + | || Type '''gnuplot '''and press '''Enter'''. |
− | || Type '''gnuplot''' | + | || Type '''gnuplot''' at the command prompt and press '''Enter''' to open '''gnuplot'''. |
− | + | ||
|- | |- | ||
− | || | + | || Press '''Ctrl+Shift+K '''. |
− | ''' | + | || I will clear the screen. |
− | || | + | |
− | + | ||
|- | |- | ||
− | || ''' | + | || Type '''plot "data.txt" using 1:2 title 'Y1' '''and Press '''Enter'''. |
− | || Here we also added legend in the same command line | + | || First let's make a plot from x and y1 data columns. |
− | + | Enter command as seen on the screen. | |
− | Next, let's make the symbol size larger | + | |
+ | |- | ||
+ | || Hover mouse next to legend text. | ||
+ | || Here we have also added the legend text in the same command line. | ||
+ | |||
+ | |- | ||
+ | || Hover mouse next to '''symbols'''. | ||
+ | || Next, let's make the symbol size larger. | ||
|- | |- | ||
|| Type '''set pointsize 1.5''' | || Type '''set pointsize 1.5''' | ||
− | Press ''' | + | Press '''Enter''' |
− | || To set symbol point size, | + | || To set the symbol point size, enter command, '''set pointsize 1.5'''. |
− | + | ||
|- | |- | ||
− | || '''replot''' | + | || Type '''replot''' and press '''Enter'''. |
− | || | + | || Enter the command '''replot''', to see the updated graph. |
− | + | ||
|- | |- | ||
− | || | + | || Narration only. |
− | || Now, | + | || Now, let’s plot both '''y1''' and '''y2''' data on the graph together. |
|- | |- | ||
− | ||'''plot "data.txt" using 1:2 title 'Y1' , "data.txt" using 1:3 title 'Y2'''' | + | || Type '''plot "data.txt" using 1:2 title 'Y1' , "data.txt" using 1:3 title 'Y2' ''' |
− | || For this purpose, use the plot command as above, in series, separated by a comma | + | and press '''Enter'''. |
+ | |||
+ | || For this purpose, use the plot command as above, in series, separated by a comma. | ||
The command is shown on the screen. | The command is shown on the screen. | ||
|- | |- | ||
− | || | + | || Point mouse on '''y''' axis. |
− | + | || Next, let's set y-axis to logarithmic scale . | |
|- | |- | ||
− | || ''' | + | || Type '''set logscale y''' and press '''Enter'''. |
− | '''replot''' | + | Type '''replot''' and press '''Enter'''. |
− | || Use command '''set space logscale space y''' to set | + | |
+ | || Use the command '''set space logscale space y''' to set logscale. | ||
'''Replot''' to see the result. | '''Replot''' to see the result. | ||
|- | |- | ||
− | || Show | + | || Show on the screen. |
− | || The | + | || The exponential data looks as a linear line due to the logarithmic scale. |
|- | |- | ||
− | || | + | || Type '''unset logscale y '''and press '''Enter'''. |
− | || To go back to linear scale for '''y axis''', use command, '''unset space logscale space y''' | + | || To go back to linear scale for '''y axis''', use command, '''unset space logscale space y'''. |
|- | |- | ||
− | || | + | || Type '''replot''' and press '''Enter'''. |
|| Please '''replot''' to see the resulting change. | || Please '''replot''' to see the resulting change. | ||
− | |||
|- | |- | ||
− | || '''plot "data.txt" using 1:3 with linespoints''' | + | || Type '''plot "data.txt" using 1:3 with linespoints''' and press '''Enter'''. |
− | || | + | || Next, let’s connect the data points for x and y2 data set, using a line. |
− | + | The command is shown on the screen. | |
|- | |- | ||
|| | || | ||
− | || Add with | + | Hover mouse next to '''linespoints'''. |
+ | || Add '''with linespoints''' command, to add a line in the graph. | ||
|- | |- | ||
− | || | + | || Hover mouse next to '''symbol'''. |
− | || | + | || Let’s change symbols to larger, filled circles and color them blue. |
− | + | ||
|- | |- | ||
− | || | + | || Type, '''plot "data.txt" using 1:3 title 'Y2' with linespoint lc 'blue' lt 1 lw 2 pt 7 ps 1.5 ''' and press '''Enter'''. |
− | + | ||
− | + | ||
|| Enter the command, as seen on the screen. | || Enter the command, as seen on the screen. | ||
− | This changes color, point style and | + | This command changes color, point style and line style. |
|- | |- | ||
− | || Hover mouse next to '''lc''' | + | || Hover mouse next to '''lc '''. |
|| Here, '''lc''' sets line color to '''blue. ''' | || Here, '''lc''' sets line color to '''blue. ''' | ||
− | We can also use hexadecimal code for | + | We can also use hexadecimal code for the chosen color. |
|- | |- | ||
− | || Hover mouse over '''lw''' | + | || Hover mouse over '''lw'''. |
− | || | + | || '''Lw''' 2 sets line width to two. |
+ | |||
|- | |- | ||
− | || Hover mouse next to '''pt''' | + | || Hover mouse next to '''pt '''. |
− | || '''Pt''' sets point type or symbol style to '''7 | + | || '''Pt 7''' sets point type or symbol style to '''7''', which is a filled circle. |
|- | |- | ||
− | || Hover mouse next '''ps''' | + | || Hover mouse next '''ps '''. |
− | || '''Ps''' sets point size or symbol size to 1.5 | + | || '''Ps 1.5''' sets point size or symbol size to 1.5 . |
|- | |- | ||
− | || Hover mouse on y-axis | + | || Show the graph with the formatting on lines and symbols. |
+ | || Notice the changes in the graph as specified in the command. | ||
+ | |||
+ | |- | ||
+ | || Hover mouse on y-axis scale in graph. | ||
|| We may wish to change the format for axis labels on many occasions. | || We may wish to change the format for axis labels on many occasions. | ||
− | Here, the y | + | Here, the '''y''' axis numbers have large values. |
|- | |- | ||
− | || | + | || Point to the y axis numbers. |
− | || We may want to use scientific notation. | + | || We may want to use scientific notation, to represent the large numbers. |
I will use set format command for this purpose. | I will use set format command for this purpose. | ||
|- | |- | ||
− | || ''' | + | || Type '''set format y '%0.2e'''' and press '''Enter'''. |
− | || Type set space format, followed by axis name. | + | || Type '''set space format''', followed by axis name. |
Here it is '''y'''. | Here it is '''y'''. | ||
+ | Follow it by space and within single quotes percent sign zero point 2 e. | ||
|- | |- | ||
− | || '''' | + | || Type '''replot''' and press '''Enter'''. |
− | || | + | || Enter the command '''replot''' to see the updated graph. |
|- | |- | ||
− | || | + | || Press '''Ctrl+Shift+K'''. |
− | || | + | || I will clear the screen. |
|- | |- | ||
− | || | + | || Type '''set border linewidth 2 lc 'red'''' and press '''Enter'''. |
− | + | Type '''replot''' and press '''Enter'''. | |
− | + | || We can also change the color of the border and the line width. | |
+ | Use the commands as shown here to change the border line color to red. | ||
+ | I am also changing the line width to two here. | ||
|- | |- | ||
− | ||''' | + | || Type '''replot''' and press '''Enter'''. |
− | ''' | + | || Please '''replot''' to see the resulting change. |
− | || | + | |
− | + | ||
− | + | ||
|- | |- | ||
− | || | + | || Type '''set timestamp''' and press''' Enter'''. |
− | || | + | || Type '''set space timestamp''' to add '''time stamp''' to the graph. |
− | Type '''set space timestamp''' to add time stamp | + | |
|- | |- | ||
− | || | + | || Type '''replot''' and press '''Enter'''. |
− | || | + | || Please '''replot''' to see the resulting change. |
+ | |||
|- | |- | ||
− | || ''' | + | || Hover the mouse next to the '''time stamp'''. |
− | ''' | + | || Notice that time stamp for the plot is displayed in the bottom of the plot. |
− | || To | + | |
− | + | |- | |
− | + | || Type '''quit''' and press '''Enter'''. | |
− | + | || To quit gnuplot, enter command '''q''' or type '''quit''' at the gnuplot prompt. | |
− | + | ||
|- | |- | ||
|| '''Slide Number 6''' | || '''Slide Number 6''' | ||
'''Summary''' | '''Summary''' | ||
− | || * | + | || To summarize, in this tutorial, we |
− | * Formatted axis type | + | * Plotted data from a file |
− | * Changed | + | * Wrote the legend title |
− | + | * Changed the symbol style and size | |
+ | * Added two datasets in the plot | ||
+ | * Formatted the axis type | ||
+ | * Changed the line color | ||
|- | |- | ||
|| '''Slide Number 7''' | || '''Slide Number 7''' | ||
'''Summary''' | '''Summary''' | ||
− | || | + | || * Formatted label style to scientific notation |
− | * | + | * Changed the border line color |
− | * | + | and |
+ | * Learned to set time stamp | ||
+ | |||
|- | |- | ||
|| '''Slide Number 8''' | || '''Slide Number 8''' | ||
+ | '''Assignment''' | ||
+ | || For assignment activity, please do the following. | ||
+ | * Type '''test''' in '''gnuplot''' prompt to see '''terminal''' capability. | ||
+ | * From the graphics window, choose different line style, symbol style and color. | ||
+ | * Plot the graph with the chosen styles using '''data.txt''' file. | ||
+ | |||
+ | |- | ||
+ | || '''Slide Number 9''' | ||
+ | '''Assignment''' | ||
+ | || * Introduce a line break in the data file between 4<sup>th</sup> and 5<sup>th</sup> line. | ||
+ | * This will give an empty row in the data file | ||
+ | and | ||
+ | * Save the file. | ||
+ | |||
+ | |- | ||
+ | || '''Slide Number 10''' | ||
+ | '''Assignment''' | ||
+ | || | ||
+ | * Plot the data with '''linespoints''' style. | ||
+ | * Observe the line break in the plot at the empty row. | ||
+ | |||
+ | |- | ||
+ | || Show test window, dotted line, triangle symbol and green color graph. | ||
+ | Show the line break in the graph. | ||
+ | || The completed assignment look similar to this. | ||
+ | |||
+ | |- | ||
+ | || '''Slide Number 11''' | ||
'''Spoken Tutorial Project''' | '''Spoken Tutorial Project''' | ||
− | || | + | || The video at the following link summarizes the '''Spoken Tutorial Project'''. |
Please download and watch it. | Please download and watch it. | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 12''' |
'''Spoken Tutorial workshops''' | '''Spoken Tutorial workshops''' | ||
− | || We conduct workshops and give certificates. | + | The '''Spoken Tutorial Project '''team: |
+ | || We conduct workshops using spoken tutorials and give certificates. | ||
Please write to us. | Please write to us. | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 13''' |
− | + | ||
'''Forum for specific questions:''' | '''Forum for specific questions:''' | ||
− | || Post your timed queries in the forum. | + | || Please Post your timed queries in the forum. |
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 14''' |
'''Acknowledgement''' | '''Acknowledgement''' | ||
− | || Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India. | + | || '''Spoken Tutorial Project''' is funded by '''NMEICT''', '''MHRD''', '''Government of India'''. |
|- | |- | ||
|| | || | ||
− | || Thank you for joining. | + | || Thank you for joining. |
+ | |||
|- | |- | ||
|} | |} |
Latest revision as of 17:39, 15 November 2019
Visual Cue | Narration |
Slide Number 1
Title Slide |
Welcome to the tutorial on Plotting Dataset from a File in gnuplot. |
Slide Number 2
Learning Objectives |
In this tutorial we will learn to,
|
Slide Number 3
Learning Objectives |
|
Slide Number 4
System and Software Requirement |
To record this tutorial, I am using
|
Slide Number 5
Pre-requisites https://www.spoken-tutorial.org |
To follow this tutorial,
|
Go to Desktop and cursor on Desktop . | Go to Desktop .
We will plot a graph using the data in a text file, named data.txt. The file is provided in the codefiles link of this tutorial. |
Show data.txt icon in Desktop directory. | I have downloaded and saved the file on Desktop. |
Double click on the icon. | Double click on the file icon to open and view the file.
The file opens in gedit text editor for me. |
Hover mouse and show on screen. | The data has three columns.
The first row consists of headings and starts with a hash. |
Point to columns. | The first column contains x axis data, 2nd and 3rd columns are two sets of y data. |
Click on the x sign. | Close the data file by clicking on the 'x' button. |
Press Ctrl+Alt+T . | Press Control, Alt & T keys together on keyboard to open the terminal. |
The terminal opens. | |
Type cd Desktop and press Enter. | Change directory to Desktop directory as seen on the screen. |
Type gnuplot and press Enter. | Type gnuplot at the command prompt and press Enter to open gnuplot. |
Press Ctrl+Shift+K . | I will clear the screen. |
Type plot "data.txt" using 1:2 title 'Y1' and Press Enter. | First let's make a plot from x and y1 data columns.
Enter command as seen on the screen. |
Hover mouse next to legend text. | Here we have also added the legend text in the same command line. |
Hover mouse next to symbols. | Next, let's make the symbol size larger. |
Type set pointsize 1.5
Press Enter |
To set the symbol point size, enter command, set pointsize 1.5. |
Type replot and press Enter. | Enter the command replot, to see the updated graph. |
Narration only. | Now, let’s plot both y1 and y2 data on the graph together. |
Type plot "data.txt" using 1:2 title 'Y1' , "data.txt" using 1:3 title 'Y2'
and press Enter. |
For this purpose, use the plot command as above, in series, separated by a comma.
The command is shown on the screen. |
Point mouse on y axis. | Next, let's set y-axis to logarithmic scale . |
Type set logscale y and press Enter.
Type replot and press Enter. |
Use the command set space logscale space y to set logscale.
Replot to see the result. |
Show on the screen. | The exponential data looks as a linear line due to the logarithmic scale. |
Type unset logscale y and press Enter. | To go back to linear scale for y axis, use command, unset space logscale space y. |
Type replot and press Enter. | Please replot to see the resulting change. |
Type plot "data.txt" using 1:3 with linespoints and press Enter. | Next, let’s connect the data points for x and y2 data set, using a line.
The command is shown on the screen. |
Hover mouse next to linespoints. |
Add with linespoints command, to add a line in the graph. |
Hover mouse next to symbol. | Let’s change symbols to larger, filled circles and color them blue. |
Type, plot "data.txt" using 1:3 title 'Y2' with linespoint lc 'blue' lt 1 lw 2 pt 7 ps 1.5 and press Enter. | Enter the command, as seen on the screen.
This command changes color, point style and line style. |
Hover mouse next to lc . | Here, lc sets line color to blue.
We can also use hexadecimal code for the chosen color. |
Hover mouse over lw. | Lw 2 sets line width to two. |
Hover mouse next to pt . | Pt 7 sets point type or symbol style to 7, which is a filled circle. |
Hover mouse next ps . | Ps 1.5 sets point size or symbol size to 1.5 . |
Show the graph with the formatting on lines and symbols. | Notice the changes in the graph as specified in the command. |
Hover mouse on y-axis scale in graph. | We may wish to change the format for axis labels on many occasions.
Here, the y axis numbers have large values. |
Point to the y axis numbers. | We may want to use scientific notation, to represent the large numbers.
I will use set format command for this purpose. |
Type set format y '%0.2e' and press Enter. | Type set space format, followed by axis name.
Here it is y. Follow it by space and within single quotes percent sign zero point 2 e. |
Type replot and press Enter. | Enter the command replot to see the updated graph. |
Press Ctrl+Shift+K. | I will clear the screen. |
Type set border linewidth 2 lc 'red' and press Enter.
Type replot and press Enter. |
We can also change the color of the border and the line width.
Use the commands as shown here to change the border line color to red. I am also changing the line width to two here. |
Type replot and press Enter. | Please replot to see the resulting change. |
Type set timestamp and press Enter. | Type set space timestamp to add time stamp to the graph. |
Type replot and press Enter. | Please replot to see the resulting change. |
Hover the mouse next to the time stamp. | Notice that time stamp for the plot is displayed in the bottom of the plot. |
Type quit and press Enter. | To quit gnuplot, enter command q or type quit at the gnuplot prompt. |
Slide Number 6
Summary |
To summarize, in this tutorial, we
|
Slide Number 7
Summary |
* Formatted label style to scientific notation
and
|
Slide Number 8
Assignment |
For assignment activity, please do the following.
|
Slide Number 9
Assignment |
* Introduce a line break in the data file between 4th and 5th line.
and
|
Slide Number 10
Assignment |
|
Show test window, dotted line, triangle symbol and green color graph.
Show the line break in the graph. |
The completed assignment look similar to this. |
Slide Number 11
Spoken Tutorial Project |
The video at the following link summarizes the Spoken Tutorial Project.
Please download and watch it. |
Slide Number 12
Spoken Tutorial workshops The Spoken Tutorial Project team: |
We conduct workshops using spoken tutorials and give certificates.
Please write to us. |
Slide Number 13
Forum for specific questions: |
Please Post your timed queries in the forum. |
Slide Number 14
Acknowledgement |
Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India. |
Thank you for joining. |