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

From Script | Spoken-Tutorial
Revision as of 17:25, 22 February 2019 by Ranipv076 (Talk | contribs)

Jump to: navigation, search
Visual Cue Narration
Slide Number 1

Title Slide Plotting datasets from file

Welcome to the tutorial on Plotting datasets from file
Slide Number 2

Learning Objectives

In this tutorial we will learn to,
  • Plot x-y graph from a dataset in a file
  • Add two plots in a graph
  • Write legend and set time stamp
  • Change line color
  • Set symbol style and size
  • Change axis format and label style


Slide Number 3

System and Software Requirement

To record this tutorial, I am using
  • Debian Linux 9 point 3
  • Gedit text editor 3.22.0 and
  • gnuplot 5.2.5
Slide Number 4

Pre-requisites

To follow this tutorial, learner's must be familiar with,
  • Basic computer and internet skills
  • Concept of graphing

and

  • High school level Mathematics skills
Go to Desktop Go to Desktop

We will plot a graph from data in a text file data dot txt The file is provided with this tutorial.

Show data.txt icon in Desktop directory. It is saved in the Desktop folder for me.
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 over mouse over hash. Data has three columns.

The first row consists of headers and starts with a hash

First column contain x data.

2nd and 3rd columns are two sets of y data.

Click on x sign Close the file by File > quit or click on the 'x' sign
Press ctrl+alt+t Press control alt t, keys together on keyboard, to open a terminal
A terminal opens.
cd Desktop Change directory to Desktop directory with command as seen on the screen.
gnuplot, clear screen, Type gnuplot in command prompt and press enter, to open gnuplot

I will bring terminal plot to top of the screen for clarity

Hight on screen,

>plot "data.txt" using 1:2 title 'Y1'

First let's make a plot from x and y1 data columns.

Enter command as seen on the screen

replot Here we also added legend in the same command line

A graphic window opens Next, let's make the symbol size larger

Type set pointsize 1.5

Press enter

To set symbol point size, type set pointsize 1.5

Press enter

replot Replot to see the updated graph

You may pause the video and explore symbol size and choose a size of your choice

Now, Say I want to compare both y1 and y2 data on x-axis
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

The command is shown on the screen.

Let's set yaxis to logarithmic scale from linear next
>set logscale y

replot

Use command set space logscale space y to set logscale.

Replot to see the result.

Show in Graphic window The exponential curve change to linear line due to the logarithmic scale
>unset logscale y To go back to linear scale for y axis, use command, unset space logscale space y
>replot Please replot to see the resulting change.


plot "data.txt" using 1:3 with linespoints Say, I desire to draw a line between data points for x and y2 data set.

I will use the command as seen on the screen.

Add with lines points in the plot command itself.
Next, let's change few graph properties.

Say, I want a larger size filled circle data points and color them blue.

Highlight on screen

>plot "data.txt" using 1:3 title 'Y2' with linespoint lc 'blue' lt 1 lw 2 pt 7 ps 1.5

Enter the command, as seen on the screen.

This 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 a chosen color.

Hover mouse over lw And lLw 2 sets line width to two
Hover mouse next to pt Pt sets point type or symbol style to 7, which is a filled circle.
Hover mouse next ps Ps sets point size or symbol size to 1.5
Hover mouse on y-axis range We may wish to change the format for axis labels on many occasions.

Here, the y-axis numbers are large.

We may want to use scientific notation.

I will use set format command for this purpose.

>Set format y Type set space format, followed by axis name.

Here it is y.

'%0.2e' and replot Follow it by percent sign 2 e within single quotes as in the video.
You may also use the following syntax for changing format and range.
>set yrange [1:1.5e5] and replot Use set space yrange space 1 colon 1 point 5e5 in square braces

This also changes format of y axis

clear screen

set border linewidth 2 lc 'red'

I will bring terminal prompt to top of the screen, for clarity.

We can also change color of the border and the line width. The commands are shown on the screen.

>set timestamp We may also want to have a time stamp with the graph.

Type set space timestamp to add time stamp

Notice time stamp for the plot is displayed on bottom of the plot
Slide Number 5

Summary

To summarize, in this tutorial, we
  • Plotted data from a file
  • Added two plots in a graph
  • Wrote legend title
  • Changed line color
Slide Number 6

Summary

* Learned to change symbol style and size
  • Formatted axis type and label style
  • Changed border line color
    and
  • Learned to set time stamp
Slide Number 7

Summary

For assignment activity, please do the following,
  • Explore numbers 0-10 for color choice for line
  • Explore symbol styles for number choice 0-9
Slide Number 8

Spoken Tutorial Project

This video summarizes the Spoken Tutorial Project

Please download and watch it.

Slide Number 9

Spoken Tutorial workshops

We conduct workshops and give certificates.

Please write to us.

Slide Number 10

Forum for specific questions:

Post your timed queries in the forum.
Slide Number 11

Acknowledgement

Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
Thank you for joining.

Contributors and Content Editors

Madhurig, Ranipv076, Snehalathak