Difference between revisions of "Gnuplot/C2/Plotting-datasets-from-file/English"
Snehalathak (Talk | contribs) |
|||
| (4 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
{|border=1 | {|border=1 | ||
| − | || '''Visual Cue''' | + | ||'''Visual Cue''' |
| − | | '''Narration''' | + | ||'''Narration''' |
|- | |- | ||
| Line 12: | Line 12: | ||
'''Learning Objectives''' | '''Learning Objectives''' | ||
|| In this tutorial we will learn to, | || In this tutorial we will learn to, | ||
| − | |||
* Plot xy graph from a dataset in a file | * Plot xy graph from a dataset in a file | ||
* Write the legend title | * Write the legend title | ||
| − | * Set symbol | + | * Set symbol style and size |
* Add two datasets in the plot | * Add two datasets in the plot | ||
* Change axis format to log scale | * Change axis format to log scale | ||
| Line 25: | Line 24: | ||
* Change the line color | * Change the line color | ||
* Format the label style to scientific notation | * Format the label style to scientific notation | ||
| − | * Format the border line | + | * Format the border line and |
| − | and | + | |
* Add time stamp | * Add time stamp | ||
| Line 33: | Line 31: | ||
'''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.3 | ||
| − | * gnuplot 5.2.6 | + | * '''gnuplot 5.2.6''' and |
| − | and | + | * '''Gedit''' 3.22.0 |
| − | * | + | |
|- | |- | ||
| Line 43: | Line 41: | ||
https://www.spoken-tutorial.org | https://www.spoken-tutorial.org | ||
|| To follow this tutorial, | || To follow this tutorial, | ||
| − | + | * Learner must be familiar with, High school Mathematics. | |
| − | * | + | |
* For pre-requisite '''gnuplot''' tutorials, please visit this site. | * For pre-requisite '''gnuplot''' tutorials, please visit this site. | ||
| Line 50: | Line 47: | ||
|| Go to Desktop and cursor on '''Desktop '''. | || Go to Desktop and cursor on '''Desktop '''. | ||
|| Go to '''Desktop''' . | || Go to '''Desktop''' . | ||
| − | We will plot a graph using the data in a '''text''' file '''data.txt'''. | + | 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. | The file is provided in the '''codefiles''' link of this tutorial. | ||
| Line 60: | Line 58: | ||
|| 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 mouse and show on screen. | || Hover mouse and show on screen. | ||
|| The data has three columns. | || The data has three columns. | ||
| − | The first row consists of headings and starts with a | + | The first row consists of headings and starts with a hash. |
|- | |- | ||
| Line 77: | Line 75: | ||
|- | |- | ||
|| Press '''Ctrl+Alt+T '''. | || Press '''Ctrl+Alt+T '''. | ||
| − | || Press '''Control, Alt''' & '''T''' keys together on keyboard to open the terminal. | + | || Press '''Control''', '''Alt''' & '''T''' keys together on keyboard to open the terminal. |
|- | |- | ||
| Line 89: | Line 87: | ||
|- | |- | ||
|| Type '''gnuplot '''and press '''Enter'''. | || Type '''gnuplot '''and press '''Enter'''. | ||
| − | || Type '''gnuplot''' at the command prompt and press | + | || Type '''gnuplot''' at the command prompt and press '''Enter''' to open '''gnuplot'''. |
|- | |- | ||
|| Press '''Ctrl+Shift+K '''. | || Press '''Ctrl+Shift+K '''. | ||
| − | || I will clear | + | || I will clear the screen. |
|- | |- | ||
| Line 101: | Line 99: | ||
|- | |- | ||
| − | || | + | || Hover mouse next to legend text. |
| − | Hover mouse next to legend text. | + | || Here we have also added the legend text in the same command line. |
| − | || | + | |
| − | Here we have also added the legend text in the same command line | + | |
| − | + | ||
|- | |- | ||
| Line 117: | Line 112: | ||
|- | |- | ||
| − | || Type''' replot '''and press '''Enter'''. | + | || Type '''replot''' and press '''Enter'''. |
| − | || Enter command replot, to see the updated graph. | + | || Enter the command '''replot''', to see the updated graph. |
|- | |- | ||
| Line 133: | Line 128: | ||
|- | |- | ||
|| Point mouse on '''y''' axis. | || Point mouse on '''y''' axis. | ||
| − | || | + | || Next, let's set y-axis to logarithmic scale . |
|- | |- | ||
|| Type '''set logscale y''' and press '''Enter'''. | || Type '''set logscale y''' and press '''Enter'''. | ||
| − | Type '''replot''' and press ''' | + | Type '''replot''' and press '''Enter'''. |
| − | || Use command '''set space logscale space y''' to set logscale. | + | || Use the command '''set space logscale space y''' to set logscale. |
'''Replot''' to see the result. | '''Replot''' to see the result. | ||
| Line 148: | Line 143: | ||
|- | |- | ||
|| Type '''unset logscale y '''and press '''Enter'''. | || Type '''unset logscale y '''and press '''Enter'''. | ||
| − | || To go back to linear scale for '''y | + | || To go back to linear scale for '''y axis''', use command, '''unset space logscale space y'''. |
|- | |- | ||
| Line 162: | Line 157: | ||
|| | || | ||
Hover mouse next to '''linespoints'''. | Hover mouse next to '''linespoints'''. | ||
| − | || Add | + | || Add '''with linespoints''' command, to add a line in the graph. |
|- | |- | ||
|| Hover mouse next to '''symbol'''. | || Hover mouse next to '''symbol'''. | ||
| − | || | + | || Let’s change symbols to larger, filled circles and color them blue. |
| − | 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''' | + | || 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 command changes color, point style and | + | This command changes color, point style and line style. |
|- | |- | ||
| Line 180: | Line 174: | ||
|- | |- | ||
| − | || Hover mouse over '''lw '''. | + | || Hover mouse over '''lw'''. |
| − | || Lw 2 sets line width to two. | + | || '''Lw''' 2 sets line width to two. |
|- | |- | ||
|| Hover mouse next to '''pt '''. | || Hover mouse next to '''pt '''. | ||
| − | || '''Pt 7''' sets point type or symbol style to '''7 | + | || '''Pt 7''' sets point type or symbol style to '''7''', which is a filled circle. |
|- | |- | ||
| Line 198: | Line 192: | ||
|| Hover mouse on y-axis scale in graph. | || 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. | || 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. | ||
| Line 209: | Line 203: | ||
|| 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. | + | Follow it by space and within single quotes percent sign zero point 2 e. |
|- | |- | ||
| − | || Type ''' | + | || Type '''replot''' and press '''Enter'''. |
| − | || Enter '''replot''' to see updated graph. | + | || Enter the command '''replot''' to see the updated graph. |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
|- | |- | ||
|| Press '''Ctrl+Shift+K'''. | || Press '''Ctrl+Shift+K'''. | ||
| − | || | + | || I will clear the screen. |
| − | I will clear the screen. | + | |
|- | |- | ||
|| Type '''set border linewidth 2 lc 'red'''' and press '''Enter'''. | || Type '''set border linewidth 2 lc 'red'''' and press '''Enter'''. | ||
Type '''replot''' and press '''Enter'''. | Type '''replot''' and press '''Enter'''. | ||
| − | || We can also change the color of the border and line width. | + | || We can also change the color of the border and the line width. |
| − | Use the commands as shown here to change the line color to red. | + | 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''' | + | || Type '''set timestamp''' and press''' Enter'''. |
| − | Type ''' | + | || Type '''set space timestamp''' to add '''time stamp''' to the graph. |
| − | || Type ''' | + | |
| + | |- | ||
| + | || Type '''replot''' and press '''Enter'''. | ||
| + | || Please '''replot''' to see the resulting change. | ||
|- | |- | ||
|| Hover the mouse next to the '''time stamp'''. | || Hover the mouse next to the '''time stamp'''. | ||
| − | || Notice that time stamp for the plot is displayed | + | || Notice that time stamp for the plot is displayed in the bottom of the plot. |
|- | |- | ||
| Line 255: | Line 246: | ||
* Plotted data from a file | * Plotted data from a file | ||
* Wrote the legend title | * Wrote the legend title | ||
| − | * Changed symbol style and size | + | * Changed the symbol style and size |
| − | * Added two | + | * Added two datasets in the plot |
* Formatted the axis type | * Formatted the axis type | ||
* Changed the line color | * Changed the line color | ||
| Line 273: | Line 264: | ||
'''Assignment''' | '''Assignment''' | ||
|| For assignment activity, please do the following. | || For assignment activity, please do the following. | ||
| − | * Type test in gnuplot prompt to see terminal capability. | + | * Type '''test''' in '''gnuplot''' prompt to see '''terminal''' capability. |
* From the graphics window, choose different line style, symbol style and color. | * From the graphics window, choose different line style, symbol style and color. | ||
| − | * Plot the graph with the chosen styles using data.txt file. | + | * Plot the graph with the chosen styles using '''data.txt''' file. |
|- | |- | ||
|| '''Slide Number 9''' | || '''Slide Number 9''' | ||
'''Assignment''' | '''Assignment''' | ||
| − | || * Introduce a line break in the data file between | + | || * 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 | + | * This will give an empty row in the data file |
| − | * Plot the data with linespoints style. | + | 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. | * Observe the line break in the plot at the empty row. | ||
| Line 291: | Line 289: | ||
|- | |- | ||
| − | || '''Slide Number | + | || '''Slide Number 11''' |
'''Spoken Tutorial Project''' | '''Spoken Tutorial Project''' | ||
| − | || The video at the following link summarizes the 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''' | ||
The '''Spoken Tutorial Project '''team: | The '''Spoken Tutorial Project '''team: | ||
| Line 304: | Line 302: | ||
|- | |- | ||
| − | || '''Slide Number | + | || '''Slide Number 13''' |
'''Forum for specific questions:''' | '''Forum for specific questions:''' | ||
|| Please 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'''. |
|- | |- | ||
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. |