Gnuplot/C2/Plotting-functions/English

From Script | Spoken-Tutorial
Revision as of 16:21, 4 December 2018 by Ranipv076 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Title of script: Plotting functions

Author: Rani Parvathy

Keywords: Video tutorial, spoken tutorial, gnuplot, sin (x), cos(x), graph, plot, replot, axis range, angle, Greek alphabet, font style, help documentation, set table, pipe output to file


Visual Cue Narration
Slide Number 1
Title Slide
Plotting functions
Welcome to the tutorial on Plotting functions
Slide Number 2
Learning Objectives


In this tutorial we will learn,


  • Plot & replot commands for 2D plotting
  • Plot three functions sin x, cos x and sin x + cos x
  • Draw grid and set limits
  • Zoom into a graph


Slide Number 3
Learning Objectives


*
Add axis labels and graph title
  • Change font style and size
  • Add Greek symbols
  • Set axis tick marks
  • Write data points to a table


Slide Number 4
System and Software Requirement


To record this tutorial, I am using


Debian Linux
Gedit 3.22.0 and
gnuplot 5.2.5 installed
Slide Number 5
Samson Microphone
To record audio, I am using 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 also.
Slide Number 6
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 7
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
Ctrl alt t


Open a terminal by pressing control alt t keys together
Depending on your operating system, please set terminal
>set term qt
press enter
I will type set space term space qt.


Press enter to execute the command.


This works for most operating systems
>gnuplot. Enter command gnuplot, to open gnuplot
Control L
The terminal prompt changes to gnuplot when program runs


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


Press control l on keypad.
>plot sin (x), press enter
Type, plot space sin x


Note that angle X is within braces and press enter
A graphical window with plot of x, sin x appear on screen
Hover mouse on graph, axes Limit of y axis is from -1 to plus 1 and x axis is from -10 to 10
Click on grid icon Click on the grid icon. This draws grid in the graph.
Hold control and zoom in with mouse scroll Hold down ctrl key and zoom in around origin, 0, 0, with scroll mouse
Notice, sin x is zero when x is zero
Show zoom in and out Using scroll wheel, zoom in and out in the graph.
Type reset, enter
Type replot, enter
To reset, enter command reset in terminal, followed by replot


Changes in graph becomes visible only after replot command
This resets limits of axis as before
Notice the legend in the graph is not clear and runs through the graph
Point mouse on legend Let's increase y-axis range, so that graph line does not run through legend.
>set yrange [-2:2] Enter command set space yrange space -2 colon 2 within square braces
>set xrange [-20:20] Change x-range with command set space xrange space -20 colon 20 in square braces
Enter replot command to see the updated graph.
Now the changed graph limits are visible.
Legend has moved upward and does not run through the data line.
>set key top left Command set space key space top space left will move legend to top left side.
>replot Do not forget to replot to see the result.
Next, let's make the axis fonts larger.


I want to set them at size 14 and in Verdana style, a bit larger than present
>set tics font “Verdana, 14”
>replot
Enter command set space tics space font Verdana comma 14 in double quotes


Replot to see the result.
Notice the larger font size in Verdana style.
set xlabel 'x (angle)' font “Verdana, 14”


Let's set x axis label as x angle next.


Please follow the commands as seen in the video


Here we are specifying the font style and size in the same command line
set ylabel 'sin (x)' font “Verdana, 14” To set y-axis label as sin x, type command, as seen in the video
To specify the style and size of axis label, add font details in the setting.
I will set the same font style and size for y axis too.
Changes in graph will become visible only after replot command.
>replot Hence type replot and enter.
Type Template:Anchor set key font ",14" Set space key space font space ,14 in double quotes command sets font size to 14.
Type help fonts To access help documentation on fonts, type help space fonts
Point mouse to cairo, gd and postscript Help command returns with 3 subtopics cairo, gd and postscript
>cairo I will type cairo to see the details and available options
You may pause the video, read & understand the details given in the help section
Ctrl c
ctrl l


Similarly you may choose to use help for any command when using gnuplot.


Press control c to exit help section


Press control l on keypad
>set title 'My first gnuplot'
I will also add a title, reading, my first gnuplot.


To add title, enter command, set space title , as seen in the video
>set title font "verdana, 18" To set title font, use the command as seen.
Note that, x axis has dimensions of angle this plot


Hence we may like to label x-axis, in terms of angle, pi
Point at the terminal


Highlight the following command and hover mouse over {/symbol p} and -2*pi


set xtics ('-4{/Symbol p}' -4*pi,'-3{/Symbol p}' -3*pi,'-2{/Symbol p}' -2*pi, '-{/Symbol p}' -pi, 0, '{/Symbol p}' pi,'2{/Symbol p}' 2*pi, '3{/Symbol p}' 3*pi, '4{/Symbol p}' 4*pi,)


Template:Anchor set xtics ('-2{/Symbol p}' -2*pi, '-{/Symbol p}' -pi, 0, '{/Symbol p}' pi,'2{/Symbol p}' 2*pi)
To change xtics to angle, type the following command as seen on screen


Here we are setting Greek pi alphabet and set it's position.
Point mouse to ('-2{/Symbol p}' and then to -2*pi This command placed label 2 pi at position 6.28 at x-axis.
X-tics is labeled, Greek symbol pi is placed at value of 3.14
Type help set xtics
For more help on formats, enter command, help space set space xtics.


Pause the video and explore more if you wish to do so.
Ctrl c
Press control c to exit help


It is also possible to add multiple functions on the same graph
To plot sin x and cos x on same graph, separate the functions by a comma
plot sin (x), cos (x)
Enter command, Plot space sin x comma cos x


Make sure, the angle x, is typed within braces


Notice the two functions plotted together
Next, add sin x plus cos x function to the graph
plot sin(x), cos(x), sin(x) + cos(x)
For this, type plot space sin(x) comma cos(x) comma sin(x) plus cos(x)


Notice the three functions plotted together
Say, next I want to get sin(x) data points in a file
To get an ascii column format output, set table command can be used
plot sin(x) First enter command set space table
plot sin(x) Type, plot space sinx
An x-y column data for sin(x) is generated on the screen
First column is x data and second column is y data points of x sinx graph
We can pipe or 'direct' the output to a text file.
>set table "table-sinx.txt"
For this, type, set space table space in double quotes table hyphen sinx dot txt


Here, the output is directed to file name table hyphen sin x dot txt
The file is stored in the directory from where we opened gnuplot in terminal.
We can remove tabular outputs with unset table command
>unset table Enter command unset space table to unset table mode
Slide Number 8
Summary


To summarize, in this tutorial, we
Learned to


Plot 2D graphs of simple functions
Added grid and set limits
Zoomed and viewed graph
Added axis labels, graph title
Changed font style and size
and
Wrote data points to table
Slide Number 9
Assignment


For assignment, plot the following functions,


tan x
Legendre polynomial
a parabola
and
Open parabola in four different quadrants
Slide Number 10
Spoken Tutorial Project


This video summarises 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.


Please write to us.

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.


This is Rani from IIT, Bombay. Thank you for joining.

Contributors and Content Editors

Madhurig, Ranipv076