Difference between revisions of "Gnuplot/C2/Plotting-datasets-from-file/English"
Line 1: | Line 1: | ||
{|border=1 | {|border=1 | ||
− | || Visual Cue | + | || '''Visual Cue''' |
− | | | + | | '''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 | ||
+ | * Set symbol, style and size | ||
* Add two plots in a graph | * Add two plots in a graph | ||
− | + | * Change axis format to log scale | |
− | + | ||
− | + | ||
− | * Change axis format | + | |
− | + | ||
|- | |- | ||
|| '''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.3 | |
− | * Debian Linux 9 | + | * gnuplot 5.2.6 |
− | * | + | and |
− | * | + | * gedit 3.22 |
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 5''' |
'''Pre-requisites''' | '''Pre-requisites''' | ||
− | || To follow this tutorial, | + | https://www.spoken-tutorial.org |
− | + | || To follow this tutorial, | |
− | + | ||
− | + | * Learners must be familiar with, High school level Mathematics. | |
− | + | * For pre-requisite gnuplot tutorials, please visit this site. | |
|- | |- | ||
− | || Go to '''Desktop''' | + | || Go to Desktop and cursor on '''Desktop '''. |
− | || Go to ''' | + | || Go to '''desktop''' . |
− | We will plot a graph | + | We will plot a graph using the data in a '''text''' file '''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. | ||
− | File opens in '''gedit''' text editor for me | + | 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 to bring terminal prompt to top of 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. |
− | A graphic window opens | + | 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. | ||
+ | A graphic window opens. | ||
+ | |||
+ | |- | ||
+ | || 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 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. |
− | || Let's set | + | || 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 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''' in the plot command itself to add a line in the graph. | ||
|- | |- | ||
− | || | + | || Hover mouse next to '''symbol'''. |
− | || Next, let's change | + | || Next, let's change the graph properties. |
− | + | 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 style line. | + | This command changes color, point style and style line. |
|- | |- | ||
− | || 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, '''which is a filled circle. | + | || '''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-axis numbers are large. | + | Here, the '''y'''-axis numbers are large values. |
|- | |- | ||
− | || | + | || Point to the y axis numbers. |
− | || We may want to use scientific notation. | + | || We may want to use scientific notation. for 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 2 e. | ||
|- | |- | ||
− | || '''' | + | || Type '''Replot''' and press '''Enter'''. |
− | || | + | || Enter '''replot''' to see updated graph. |
|- | |- | ||
− | || | + | || Type '''set yrange [1:1.5e5] '''and press '''Enter'''. |
− | || | + | Type '''Replot''' and press '''Enter'''. |
+ | || use the following syntax for changing format and range. | ||
+ | Use '''set space yrange space in square brackets 1 colon 1.5e5 ''' | ||
|- | |- | ||
− | || | + | || Press '''Ctrl+Shift+K'''. |
− | || | + | || This command also changes the format of y-axis. |
− | This also changes format of | + | 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 line width. |
− | We can also change color of the border and | + | Use the commands as shown here to change the line color to red. |
− | + | ||
|- | |- | ||
− | || | + | || Narration only. |
− | || We may also want to have a time stamp with the graph. | + | || We may also want to have a '''time stamp''' with the graph. |
− | + | ||
|- | |- | ||
− | || | + | || Type '''set timestamp''' and press''' enter'''. |
− | || | + | Type '''replot''' and press Enter. |
+ | || Type '''set space timestamp''' to add '''time stamp'''. | ||
+ | |||
|- | |- | ||
− | || '''Slide Number | + | || Hover the mouse next to the '''time stamp'''. |
+ | || Notice that time stamp for the plot is displayed at 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''' | '''Summary''' | ||
|| To summarize, in this tutorial, we | || To summarize, in this tutorial, we | ||
* Plotted data from a file | * Plotted data from a file | ||
+ | * Wrote the legend title | ||
+ | * Changed symbol style and size | ||
* Added two plots in a graph | * Added two plots in a graph | ||
− | * | + | * Formatted the axis type |
− | * Changed line color | + | * Changed the line color |
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 7''' |
'''Summary''' | '''Summary''' | ||
− | || | + | || * Formatted label style to scientific notation |
− | * Formatted | + | * Changed the border line color |
− | * Changed border line color | + | and |
* Learned to set time stamp | * 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 4th and 5th line. | ||
+ | * This will give an empty row in the data file and save the file. | ||
+ | * 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 10''' | ||
'''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 11''' |
'''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 12''' |
− | + | ||
'''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 13''' |
'''Acknowledgement''' | '''Acknowledgement''' | ||
|| Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India. | || Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India. | ||
Line 269: | Line 314: | ||
|- | |- | ||
|| | || | ||
− | || Thank you for joining. | + | || Thank you for joining. |
+ | |||
|- | |- | ||
|} | |} |
Revision as of 17:23, 18 October 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 |
* Change the line color
and
|
Slide Number 4
System and Software Requirement |
To record this tutorial, I am using
and
|
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 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.
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 to bring terminal prompt to top of 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. A graphic window opens. |
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 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. | Let's set y-axis to logarithmic scale . |
Type set logscale y and press Enter.
Type replot and press enter. |
Use 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 in the plot command itself to add a line in the graph. |
Hover mouse next to symbol. | Next, let's change the graph properties.
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 style line. |
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 are large values. |
Point to the y axis numbers. | We may want to use scientific notation. for 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 2 e. |
Type Replot and press Enter. | Enter replot to see updated graph. |
Type set yrange [1:1.5e5] and press Enter.
Type Replot and press Enter. |
use the following syntax for changing format and range.
Use set space yrange space in square brackets 1 colon 1.5e5 |
Press Ctrl+Shift+K. | This command also changes the format of y-axis.
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 line width.
Use the commands as shown here to change the line color to red. |
Narration only. | We may also want to have a time stamp with the graph. |
Type set timestamp and press enter.
Type replot and press Enter. |
Type set space timestamp to add time stamp. |
Hover the mouse next to the time stamp. | Notice that time stamp for the plot is displayed at 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.
|
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 10
Spoken Tutorial Project |
The video at the following link summarizes the Spoken Tutorial Project.
Please download and watch it. |
Slide Number 11
Spoken Tutorial workshops The Spoken Tutorial Project team: |
We conduct workshops using spoken tutorials and give certificates.
Please write to us. |
Slide Number 12
Forum for specific questions: |
Please Post your timed queries in the forum. |
Slide Number 13
Acknowledgement |
Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India. |
Thank you for joining. |