Gnuplot/C2/Plotting-datasets-from-file/English

From Script | Spoken-Tutorial
Revision as of 16:16, 30 October 2019 by Ranipv076 (Talk | contribs)

Jump to: navigation, search
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
Slide Number 5

Pre-requisites https://www.spoken-tutorial.org

To follow this tutorial,
  • Learners 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 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
  • Plotted data from a file
  • Wrote the legend title
  • Changed symbol style and size
  • Added two plots in a graph
  • 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.
  • 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

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.

Contributors and Content Editors

Madhurig, Ranipv076, Snehalathak