Difference between revisions of "Gnuplot/C2/Plotting-datasets-from-file/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 24: 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 34: Line 33:
  
 
* '''Debian Linux''' 9.3
 
* '''Debian Linux''' 9.3
* '''gnuplot 5.2.6'''
+
* '''gnuplot 5.2.6''' and  
and  
+
 
* '''Gedit''' 3.22.0
 
* '''Gedit''' 3.22.0
  
Line 50: Line 48:
 
|| Go to '''Desktop''' .
 
|| Go to '''Desktop''' .
 
We will plot a graph using the data in a '''text''' file, named '''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.
  

Revision as of 16:29, 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,
  • Plot xy graph from a dataset in a file
  • Write the legend title
  • Set symbol style and size
  • Add two datasets in the plot
  • Change axis format to log scale
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

To record this tutorial, I am using
  • Debian Linux 9.3
  • gnuplot 5.2.6 and
  • Gedit 3.22.0
Slide Number 5

Pre-requisites 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 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
  • Plotted data from a file
  • Wrote the legend title
  • Changed the symbol style and size
  • Added two plots in the plot
  • Formatted the axis type
  • Changed the line color
Slide Number 7

Summary

* Formatted label style to scientific notation
  • Changed the border line color

and

  • Learned to set time stamp


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.
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

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.

Contributors and Content Editors

Madhurig, Ranipv076, Snehalathak