Gnuplot/C2/Plotting-datasets-from-file/English
From Script | Spoken-Tutorial
Title of script: Plotting datasets from file
Author: Rani Parvathy
Keywords: gnuplot, video tutorial, spoken tutorial, plot data from file, plot more than one graph, change line color, set key, set symbol size, month, year, date formatting
Visual Cue | Narration |
---|---|
Slide Number 1
Title Slide
Plotting datasets from file
|
Welcome to the tutorial on Plotting datasets from a file |
Slide Number 2
Learning Objectives
|
In this tutorial we will learn to,
|
Slide Number 3
System and Software Requirement
|
To record this tutorial, I am using
Debian Linux
Gedit 3.22.0 and
have gnuplot 5.2.5 installed
|
Slide Number 4
Samson Microphone
|
To record audio, Samson USB portable microphone was used.
The model number SAGOMIC
I bought it from amazon website, for about rupees four thousand
It may be available in other websites.
|
Slide Number 5
Pre-requisites
|
To follow this tutorial, learner's must be familiar with,
Basic computer and internet skills
Have concept of graphing
and
Have high school level Mathematics skills |
Slide Number 6
Pre-requisites
|
Please locate this tutorial on our web page, spoken hyphen tutorial dot org
Pre-requisite spoken tutorials, if any, will be mentioned in this page
|
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
|
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 as seen on the screen. |
Depending on your operating system, please set the terminal | |
set term qt | I will type set space term space qt.
This works for most operating systems
|
gnuplot | Type gnuplot in command prompt and press enter, to open gnuplot
I will Press control L to bring terminal prompt to top of 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 | Replot to see the graph
Here we also added legend in the same command line
A graphic window opens
Next, let's make 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 | |
Highlight
>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 y-axis 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.
|
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 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 | Lw 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 |
We may wish to change the format for axis labels on many occasions. | |
Hover mouse on y-axis range | 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' | 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]
ctrl -L
|
Use set space yrange space 1 colon 1 point 5e5 in square braces
This also changes format of y axis
I will press control l to bring terminal prompt to top of the screen for clarity.
|
set border linewidth 2 lc 'red' | We can also change color of the border and line width.
The commands are shown on the screen.
|
We may also want to have a time stamp with the graph. | |
>set timestamp | Type set space timestamp to add time stamp |
Notice time stamp for the plot is displayed on bottom of the plot | |
Slide Number 7
Summary
|
To summarize, in this tutorial, we
|
Slide Number 8
Summary
|
* Learned to change symbol style and size
|
Slide Number 9
Summary
|
For assignment activity, please do the following,
|
Slide Number 10
Spoken Tutorial Project
|
This video summarizes the Spoken Tutorial Project
If you do not have good bandwidth, you may download and watch it.
|
Slide Number 11
Spoken Tutorial workshops
|
We conduct workshops using spoken tutorials and give certificates.
|
Slide Number 12
Forum for specific questions: *
|
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. |