Difference between revisions of "Gnuplot/C2/Plotting-functions/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 2: Line 2:
 
||'''Visual Cue'''
 
||'''Visual Cue'''
 
||'''Narration'''
 
||'''Narration'''
 
 
 
 
{|
 
|-
 
  
 
|-
 
|-
Line 23: Line 17:
 
* Draw grid and set limits  
 
* Draw grid and set limits  
 
* Zoom in and zoom out of a plot
 
* Zoom in and zoom out of a plot
 
  
 
|-
 
|-
Line 32: Line 25:
 
* Change font '''style''' and size
 
* Change font '''style''' and size
 
* Add '''Greek symbols'''
 
* Add '''Greek symbols'''
* Set axis''' tick marks ''' and
+
* Set axis '''tick marks '''  
* Save the data points to a file.
+
and
 
+
* Save the data points to a file
  
 
|-
 
|-
 
|| '''Slide Number 3'''
 
|| '''Slide Number 3'''
 
'''System and Software Requirement'''
 
'''System and Software Requirement'''
 
 
 
 
|| To record this tutorial, I am using
 
|| To record this tutorial, I am using
 
  
 
* '''Debian Linux''' 9.3
 
* '''Debian Linux''' 9.3
 
* '''gnuplot''' 5.2.6
 
* '''gnuplot''' 5.2.6
 +
and
 
* '''gedit text editor''' 3.22
 
* '''gedit text editor''' 3.22
  
Line 54: Line 44:
 
|| To follow this tutorial,  
 
|| To follow this tutorial,  
  
* Learners must be familiar with high school level Mathematics.
+
* Learner must be familiar with high school level Mathematics
* For pre-requisite gnuplot tutorials, please visit this site.
+
* For prerequisite gnuplot tutorials, please visit this site
  
 
|-
 
|-
|| Press '''Ctrl Alt T'''
+
|| Press '''Ctrl Alt T''' .
 
|| Open a '''terminal''' by pressing '''Ctrl, Alt''' and''' T''' keys simultaneously.
 
|| Open a '''terminal''' by pressing '''Ctrl, Alt''' and''' T''' keys simultaneously.
  
 
|-
 
|-
|| Type cd Desktop and press '''Enter'''
+
|| Type cd Desktop and press '''Enter'''.
 
|| A terminal opens.  
 
|| A terminal opens.  
 
Change directory to '''Desktop''' as seen.
 
Change directory to '''Desktop''' as seen.
  
 
|-
 
|-
|| '''>gnuplot'''
+
|| Type '''gnuplot''' and press '''Enter'''.
Press '''Enter'''
+
 
|| In the '''terminal''', type '''gnuplot''' and press '''Enter'''.
 
|| In the '''terminal''', type '''gnuplot''' and press '''Enter'''.
  
 
|-
 
|-
|| Hover mouse near gnuplot prompt  
+
|| Hover mouse near gnuplot prompt.
 
|| The '''prompt''' changes to '''gnuplot prompt.'''
 
|| The '''prompt''' changes to '''gnuplot prompt.'''
  
Line 79: Line 68:
  
 
|-
 
|-
|| Press''' Ctrl shift K'''
+
|| Press''' Ctrl shift K'''.
|| I will clear the '''terminal.'''
+
|| I will clear the '''terminal'''.
  
 
|-
 
|-
|| Type '''plot sin (x)'''  
+
|| Type '''plot sin (x)''' and Press '''Enter'''.
Press '''Enter'''
+
|| Now type '''plot space sin (x)'''.
|| Now type '''plot space sin (x)'''
+
 
Note that angle '''x''' is within parentheses.
 
Note that angle '''x''' is within parentheses.
  
 
|-
 
|-
|| Point to graphical window
+
|| Point to graphical window.
|| A graphical window with plot of '''sin(x) '''versus''' x '''appears on the screen.
+
|| A graphical window with plot of '''sin(x)''' versus '''x''' appears on the screen.
  
 
|-
 
|-
 
|| Hover mouse on graph, axes.
 
|| Hover mouse on graph, axes.
 
|| The limit of the '''Y''' axis is from minus 1 to plus 1.
 
|| The limit of the '''Y''' axis is from minus 1 to plus 1.
And the '''X '''axis is from -10 to 10.
+
And the '''X''' axis is from -10 to 10.
  
 
|-
 
|-
|| Type '''set grid'''
+
|| Type '''set grid''' and press '''Enter'''.
Press '''Enter'''
+
|| Come back to the '''terminal''' and type the command''' set space grid'''.
|| Come back to the '''terminal''' and type the command''' set space grid.'''
+
  
 
|-
 
|-
|| Type '''replot'''
+
|| Type '''replot''' and press '''Enter'''
Press '''Enter'''
+
 
|| Then type''' replot''' to see the grid in the graph.
 
|| Then type''' replot''' to see the grid in the graph.
  
 
|-
 
|-
|| Hold Ctrl and zoom in with mouse scroll
+
|| Hold Ctrl and zoom in with mouse scroll.
 
|| Hold down the Control key and move the mouse scroll wheel to zoom in and zoom out.
 
|| Hold down the Control key and move the mouse scroll wheel to zoom in and zoom out.
  
 
|-
 
|-
|| Point to '''sin x '''and '''x'''
+
|| Point to '''sin x '''and '''x'''.
 
|| Observe that '''sin x''' is zero when '''x''' is zero.
 
|| Observe that '''sin x''' is zero when '''x''' is zero.
  
Line 120: Line 106:
  
 
|-
 
|-
|| Type '''reset'''  
+
|| Type '''reset''' and  press '''Enter'''.
Press '''Enter'''
+
|| To '''reset''', type the '''command reset''' in the '''terminal''', followed by '''replot'''.
|| To '''reset''', type the '''command reset''' in the '''terminal''', followed by '''replot.'''
+
  
 
|-
 
|-
|| Type '''replot'''
+
|| Type '''replot''' and press '''Enter'''.
Press '''Enter'''
+
|| Changes in the graph become visible only after executing the '''replot '''command.
|| Changes in the graph become visible only after executing the '''replot '''command'''.'''
+
  
 
|-
 
|-
|| Point to the '''legend'''
+
|| Point to the '''legend'''.
 
|| Notice that the '''legend''' is on the top right side in the graph.
 
|| Notice that the '''legend''' is on the top right side in the graph.
 
It is not clear and intersects the graph.
 
It is not clear and intersects the graph.
Line 136: Line 120:
 
|-
 
|-
 
|| Point mouse on the '''legend'''.
 
|| Point mouse on the '''legend'''.
|| Let's increase '''y axis range''', so that the graph line does not intersect the '''legend.'''
+
|| Let's increase '''y axis range''', so that the graph line does not intersect the '''legend'''.
  
 
|-
 
|-
|| Type '''set yrange [-2:2]'''
+
|| Type '''set yrange [-2:2]''' and
Press '''Enter'''
+
press '''Enter'''.
 
|| Type '''set space yrange space -2 colon 2''' within square brackets.
 
|| Type '''set space yrange space -2 colon 2''' within square brackets.
  
 
|-
 
|-
|| Type '''set xrange [-20:20]'''
+
|| Type '''set xrange [-20:20]''' and
Press '''Enter'''
+
Press '''Enter'''.
|| I will also change '''x '''axis range'''.'''
+
|| I will also change '''x '''axis range.
 
Enter command, '''set space xrange space -20 colon 20 '''within square brackets.
 
Enter command, '''set space xrange space -20 colon 20 '''within square brackets.
  
 
|-
 
|-
|| Type '''replot'''
+
|| Type '''replot''' and
 
Press '''Enter'''
 
Press '''Enter'''
 
|| Type '''replot '''to see the updated graph.
 
|| Type '''replot '''to see the updated graph.
Line 163: Line 147:
  
 
|-
 
|-
|| Type '''set key top left'''
+
|| Type '''set key top left''' and press '''Enter'''
Press '''Enter'''
+
 
|| Type '''set space key space top space left''' to move the '''legend''' to the top left side.
 
|| Type '''set space key space top space left''' to move the '''legend''' to the top left side.
  
 
|-
 
|-
|| '''Type replot'''
+
|| '''Type replot''' and press '''Enter'''.
Press '''Enter'''
+
 
|| Do not forget to '''replot''' to see the result.
 
|| Do not forget to '''replot''' to see the result.
  
Line 178: Line 160:
  
 
|-
 
|-
|| Type '''set tics font “Verdana, 14”'''  
+
|| Type '''set tics font “Verdana, 14”''' and press '''Enter'''.
Press '''Enter'''
+
 
|| Type this '''command''' as shown here, to change the font size and '''style'''.
 
|| Type this '''command''' as shown here, to change the font size and '''style'''.
 
'''Replot''' to see the result.
 
'''Replot''' to see the result.
Line 188: Line 169:
  
 
|-
 
|-
|| Type '''set xlabel 'x (angle)' font “Verdana, 14”'''
+
|| Type '''set xlabel 'x (angle)' font “Verdana, 14”'''.
 
Press '''Enter'''
 
Press '''Enter'''
 
|| Let's set '''x axis label''' as '''x angle'''.  
 
|| Let's set '''x axis label''' as '''x angle'''.  
 
Type the '''command''' as shown here.
 
Type the '''command''' as shown here.
Here we are specifying the '''label''', '''font''' '''style''' and size in a single '''command.'''
+
Here we are specifying the '''label''', '''font''' '''style''' and size in a single command.
  
 
|-
 
|-
|| Type '''set ylabel 'sin (x)' font “Verdana, 14”'''
+
|| Type '''set ylabel 'sin (x)' font “Verdana, 14”''' and press '''Enter'''.
Press '''Enter'''
+
 
|| To set '''y axis label''' as '''sin x''', type the '''command''', as shown here.
 
|| To set '''y axis label''' as '''sin x''', type the '''command''', as shown here.
  
 
|-
 
|-
|| Only narration
+
|| Only narration.
 
|| We are using the same font size and style for y axis too.
 
|| We are using the same font size and style for y axis too.
  
 
|-
 
|-
|| Type '''replot'''
+
|| Type '''replot''' and
 
Press '''Enter'''
 
Press '''Enter'''
 
|| Type '''replot''' and press '''Enter'''.  
 
|| Type '''replot''' and press '''Enter'''.  
Line 213: Line 193:
  
 
|-
 
|-
|| Type '''set key font ",16"'''
+
|| Type '''set key font ",16"''' and
 
Press '''Enter'''
 
Press '''Enter'''
 
|| Type  
 
|| Type  
'''set space key space font space '''within double quotes '''comma 16 '''
+
'''set space key space font space '''within double quotes '''comma 16 '''.
 
This '''command''' sets the '''legend '''font size to 16.  
 
This '''command''' sets the '''legend '''font size to 16.  
  
 
|-
 
|-
|| Press '''Ctrl+Alt+K'''
+
|| Press '''Ctrl+Alt+K'''.
 
|| I will clear the terminal.
 
|| I will clear the terminal.
  
 
|-
 
|-
|| Type''' help fonts'''
+
|| Type''' help fonts''' and
 
Press '''Enter'''
 
Press '''Enter'''
 
|| To access '''help''' documentation on fonts, type '''help space fonts'''.
 
|| To access '''help''' documentation on fonts, type '''help space fonts'''.
Line 230: Line 210:
 
|-
 
|-
 
|| Point mouse to '''cairo''', '''gd''' and '''postscript'''
 
|| Point mouse to '''cairo''', '''gd''' and '''postscript'''
|| Help command returns with 3 subtopics '''cairo''', '''gd''' and '''postscript.'''
+
|| Help command returns with 3 subtopics '''cairo''', '''gd''' and '''postscript'''.
 
|-
 
|-
|| Type '''cairo'''
+
|| Type '''cairo''' and
 
Press '''Enter'''
 
Press '''Enter'''
 
|| I will type '''cairo''' to see the details and available options.
 
|| I will type '''cairo''' to see the details and available options.
Line 241: Line 221:
  
 
|-
 
|-
|| Mouse in '''Help section'''
+
|| Mouse in '''Help section'''.
 
|| You may pause the video and read the details given in the '''help''' section.
 
|| You may pause the video and read the details given in the '''help''' section.
  
 
|-
 
|-
 
|| Press '''Ctrl C'''
 
|| Press '''Ctrl C'''
|| Once done, press '''Control '''and '''C''' keys to exit the '''help section.'''
+
|| Once done, press '''Control '''and '''C''' keys to exit the '''help section'''.
  
 
|-
 
|-
|| '''Ctrl L in Ubuntu'''
+
|| '''Ctrl+L in Ubuntu''' and
'''Ctrl Shift K in Debian'''
+
'''Ctrl+Shift+K in Debian'''.
 
|| I will clear the screen.
 
|| I will clear the screen.
 
I wish to add a title to my graph.
 
I wish to add a title to my graph.
  
 
|-
 
|-
|| Type '''set title 'My first gnuplot''''
+
|| Type '''set title 'My first gnuplot'''' and press '''Enter'''.
Press '''Enter'''
+
 
|| To add a title, type '''set title '''command, as shown here.  
 
|| To add a title, type '''set title '''command, as shown here.  
 
Followed by the title of the graph in single quotes.
 
Followed by the title of the graph in single quotes.
  
 
|-
 
|-
|| Type '''set title font "verdana, 18"'''
+
|| Type '''set title font "verdana, 18"''' and press '''Enter'''.
Press '''Enter'''
+
 
|| To set the title font, type the command as shown here.
 
|| To set the title font, type the command as shown here.
  
 
|-
 
|-
|| '''Point to x axis'''
+
|| '''Point to x axis'''.
 
|| In the '''sinx versus x''' plot, dimensions of '''x axis''' is angle.
 
|| In the '''sinx versus x''' plot, dimensions of '''x axis''' is angle.
Hence we may want to label '''X''' axis in terms of angle, '''π.'''
+
Hence we may want to label '''X''' axis in terms of angle, '''π'''.
  
 
|-
 
|-
 
|| In the terminal, type,
 
|| In the terminal, type,
'''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,)'''
+
'''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,)''' and
'''>enter'''
+
press'''Enter'''.
 
|| To change '''X ticks''' to angle, type the following '''command''' as shown on the screen.
 
|| To change '''X ticks''' to angle, type the following '''command''' as shown on the screen.
 
Here we are using the '''Greek''' alphabet''' pi '''and setting its position.
 
Here we are using the '''Greek''' alphabet''' pi '''and setting its position.
  
 
|-
 
|-
|| Point mouse to '''('2{/Symbol p}'''' and then to '''2*pi'''
+
|| Point mouse to '''('2{/Symbol p}'''' and then to '''2*pi'''.
 
|| This '''command''' places, '''Greek symbol pi''', at the value of 3.14.
 
|| This '''command''' places, '''Greek symbol pi''', at the value of 3.14.
 
Label 2'''π''' is at position 6.28 on the '''X''' axis.
 
Label 2'''π''' is at position 6.28 on the '''X''' axis.
  
 
|-
 
|-
|| Point to 2'''π''' and 4'''π'''.
+
|| Point to '''''' and ''''''.
 
|| Multiples of pi are placed at their respective positions.  
 
|| Multiples of pi are placed at their respective positions.  
 
|-
 
|-
 
|| Type '''help set xtics'''
 
|| Type '''help set xtics'''
 
Press '''Enter'''
 
Press '''Enter'''
|| For more help on the formats of '''X tics''', type the command '''help space set space xtics.'''
+
|| For more help on the formats of '''X tics''', type the command '''help space set space xtics'''.
  
 
|-
 
|-
|| Press '''Ctrl C'''
+
|| Press '''Ctrl C'''.
 
|| Press '''Ctrl''' and''' C''' keys to exit the '''help '''section.
 
|| Press '''Ctrl''' and''' C''' keys to exit the '''help '''section.
  
 
|-
 
|-
 +
|| Press '''Ctrl+Shift+K in Debian'''.
 
|| I will clear the terminal.
 
|| I will clear the terminal.
  
Line 302: Line 281:
  
 
|-
 
|-
|| Type '''plot sin (x), cos (x) '''
+
|| Type '''plot sin (x), cos (x) ''' and press '''Enter'''.
Press '''Enter'''
+
 
|| To plot '''sin x '''and '''cos x '''on the same graph, separate the '''functions''' by a comma.
 
|| To plot '''sin x '''and '''cos x '''on the same graph, separate the '''functions''' by a comma.
 
Type '''plot space sin x comma cos x'''  
 
Type '''plot space sin x comma cos x'''  
Line 309: Line 287:
  
 
|-
 
|-
|| Point to the graph window
+
|| Point to the graph window.
 
|| Notice that the two '''functions''' are plotted together now.
 
|| Notice that the two '''functions''' are plotted together now.
  
 
|-
 
|-
|| Only narration
+
|| Only narration.
 
|| Next, we will add '''sin (x) plus cos (x) function''' to the same graph.
 
|| Next, we will add '''sin (x) plus cos (x) function''' to the same graph.
  
 
|-
 
|-
|| Type '''plot sin(x), cos(x), sin(x) + cos(x) '''
+
|| Type '''plot sin(x), cos(x), sin(x) + cos(x) ''' and press '''Enter'''.
Press '''Enter'''
+
 
|| For this, type '''plot space sin(x) comma cos(x) comma sin(x) plus cos(x)''' .
 
|| For this, type '''plot space sin(x) comma cos(x) comma sin(x) plus cos(x)''' .
  
 
|-
 
|-
|| Point to the graph window
+
|| Point to the graph window.
 
|| Notice that all 3 '''functions''' are plotted together on the same graph now.
 
|| Notice that all 3 '''functions''' are plotted together on the same graph now.
 
Next, let’s learn how to get '''sin(x) data points '''into a file.
 
Next, let’s learn how to get '''sin(x) data points '''into a file.
  
 
|-
 
|-
|| Only narration
+
|| Only narration.
 
|| To get an '''ASCII column format''' output, '''set table command '''can be used.
 
|| To get an '''ASCII column format''' output, '''set table command '''can be used.
  
 
|-
 
|-
|| Type '''set space table'''
+
|| Type '''set space table''' and press '''Enter'''.
Press '''Enter'''
+
 
|| First type '''set space table'''.
 
|| First type '''set space table'''.
  
 
|-
 
|-
|| '''Enter command plot sin(x) '''and press '''Enter'''
+
|| '''Enter command plot sin(x) '''and press '''Enter'''.
 
|| Then type '''plot space sin(x)'''.
 
|| Then type '''plot space sin(x)'''.
  
Line 344: Line 320:
  
 
|-
 
|-
|| Highlight first column
+
|| Highlight first column.
Highlight second column
+
Highlight second column.
 
|| The first column is '''x data''' and the second column is''' y data'''.
 
|| The first column is '''x data''' and the second column is''' y data'''.
 
They are the '''points''' of '''sin''' '''x '''versus '''x''' graph.
 
They are the '''points''' of '''sin''' '''x '''versus '''x''' graph.
Line 355: Line 331:
  
 
|-
 
|-
|| Type '''set table "table-sinx.txt"'''.
+
|| Type '''set table "table-sinx.txt"''' and press '''Enter'''
Press '''Enter'''
+
|| For this, type '''set space table space '''within double quotes''' sinx dot txt'''.
|| For this, type '''set space table space '''within double quotes''' sinx dot txt'''
+
  
 +
Here '''sinx dot txt '''is the output filename.
  
Here '''sinx dot txt '''is the output filename.
 
 
|-
 
|-
|| Type '''plot sin(x)'''
+
||Type '''plot sin(x)''' and press '''Enter'''.
Press '''Enter'''
+
 
+
 
+
 
+
 
|| Then, type '''plot space sin(x)'''.
 
|| Then, type '''plot space sin(x)'''.
 
The output is saved to the file '''sin x dot txt'''.
 
The output is saved to the file '''sin x dot txt'''.
The data is not seen on the screen,
+
The data is not seen on the screen.
  
 
|-
 
|-
Line 376: Line 347:
  
 
|-
 
|-
|| Type '''unset table'''
+
|| Type '''unset table''' and press '''Enter'''.
Press '''Enter'''
+
 
|| Type '''unset space table''' to exit the tabular output mode.
 
|| Type '''unset space table''' to exit the tabular output mode.
  
 
|-
 
|-
 
|| Enter '''q'''
 
|| Enter '''q'''
|| Then type '''quit''' or '''q''' to quit '''gnuplot.'''
+
|| Then type '''quit''' or '''q''' to quit '''gnuplot'''.
  
 
|-
 
|-
Line 388: Line 358:
 
'''Summary'''
 
'''Summary'''
 
|| Let’s summarize.
 
|| Let’s summarize.
In this tutorial, we plotted '''2D''' graphs of '''functions.'''
+
In this tutorial, we plotted '''2D''' graphs of '''functions'''.
  
 
We also  
 
We also  
Line 394: Line 364:
 
* Zoomed in and zoomed out of the graph
 
* Zoomed in and zoomed out of the graph
 
* Added axis labels and graph title  
 
* Added axis labels and graph title  
* Changed font style and size and  
+
* Changed font style and size  
 +
and  
 
* Saved the '''data points''' to a file
 
* Saved the '''data points''' to a file
  
Line 436: Line 407:
 
||  
 
||  
 
|| This is Rani from IIT, Bombay. Thank you for joining.
 
|| This is Rani from IIT, Bombay. Thank you for joining.
 
|-
 
|}
 
  
 
|-
 
|-
 
|}
 
|}

Revision as of 16:26, 14 October 2019

Visual Cue Narration
Slide Number 1

Title Slide Plotting functions

Welcome to the tutorial on Plotting functions in gnuplot.
Slide Number 2

Learning Objectives

In this tutorial we will learn,
  • Plot and replot commands for 2D plotting
  • Plot three functions: sin x, cos x and sin x plus cos x
  • Draw grid and set limits
  • Zoom in and zoom out of a plot
Slide Number 3

Learning Objectives

* Add axis labels and graph title
  • Change font style and size
  • Add Greek symbols
  • Set axis tick marks

and

  • Save the data points to a file
Slide Number 3

System and Software Requirement

To record this tutorial, I am using
  • Debian Linux 9.3
  • gnuplot 5.2.6

and

  • gedit text editor 3.22
Slide Number 4

Pre-requisites

To follow this tutorial,
  • Learner must be familiar with high school level Mathematics
  • For prerequisite gnuplot tutorials, please visit this site
Press Ctrl Alt T . Open a terminal by pressing Ctrl, Alt and T keys simultaneously.
Type cd Desktop and press Enter. A terminal opens.

Change directory to Desktop as seen.

Type gnuplot and press Enter. In the terminal, type gnuplot and press Enter.
Hover mouse near gnuplot prompt. The prompt changes to gnuplot prompt.

To execute a command in the terminal, press Enter after typing it. I will not mention this separately.

Press Ctrl shift K. I will clear the terminal.
Type plot sin (x) and Press Enter. Now type plot space sin (x).

Note that angle x is within parentheses.

Point to graphical window. A graphical window with plot of sin(x) versus x appears on the screen.
Hover mouse on graph, axes. The limit of the Y axis is from minus 1 to plus 1.

And the X axis is from -10 to 10.

Type set grid and press Enter. Come back to the terminal and type the command set space grid.
Type replot and press Enter Then type replot to see the grid in the graph.
Hold Ctrl and zoom in with mouse scroll. Hold down the Control key and move the mouse scroll wheel to zoom in and zoom out.
Point to sin x and x. Observe that sin x is zero when x is zero.
Show zoom in and out. Let us reset the limits of the axes as before.
Type reset and press Enter. To reset, type the command reset in the terminal, followed by replot.
Type replot and press Enter. Changes in the graph become visible only after executing the replot command.
Point to the legend. Notice that the legend is on the top right side in the graph.

It is not clear and intersects the graph.

Point mouse on the legend. Let's increase y axis range, so that the graph line does not intersect the legend.
Type set yrange [-2:2] and

press Enter.

Type set space yrange space -2 colon 2 within square brackets.
Type set xrange [-20:20] and

Press Enter.

I will also change x axis range.

Enter command, set space xrange space -20 colon 20 within square brackets.

Type replot and

Press Enter

Type replot to see the updated graph.
Now the changed graph limits are visible.
Point to the legend. The legend has moved up and does not intersect the data line anymore.
Type set key top left and press Enter Type set space key space top space left to move the legend to the top left side.
Type replot and press Enter. Do not forget to replot to see the result.
Hover mouse next to axis font. Next, let's make the axes fonts larger.

I want to set them at size 14 and in Verdana style.

Type set tics font “Verdana, 14” and press Enter. Type this command as shown here, to change the font size and style.

Replot to see the result.

Hover mouse next to axis font. Notice the larger font size in Verdana style.
Type set xlabel 'x (angle)' font “Verdana, 14”.

Press Enter

Let's set x axis label as x angle.

Type the command as shown here. Here we are specifying the label, font style and size in a single command.

Type set ylabel 'sin (x)' font “Verdana, 14” and press Enter. To set y axis label as sin x, type the command, as shown here.
Only narration. We are using the same font size and style for y axis too.
Type replot and

Press Enter

Type replot and press Enter.
Only narration Now, let’s see how to change the font in the legend.
Type set key font ",16" and

Press Enter

Type

set space key space font space within double quotes comma 16 . This command sets the legend font size to 16.

Press Ctrl+Alt+K. I will clear the terminal.
Type help fonts and

Press Enter

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.
Type cairo and

Press Enter

I will type cairo to see the details and available options.
Only narration Similarly you may choose to use help for any command when using gnuplot.
Mouse in Help section. You may pause the video and read the details given in the help section.
Press Ctrl C Once done, press Control and C keys to exit the help section.
Ctrl+L in Ubuntu and

Ctrl+Shift+K in Debian.

I will clear the screen.

I wish to add a title to my graph.

Type set title 'My first gnuplot' and press Enter. To add a title, type set title command, as shown here.

Followed by the title of the graph in single quotes.

Type set title font "verdana, 18" and press Enter. To set the title font, type the command as shown here.
Point to x axis. In the sinx versus x plot, dimensions of x axis is angle.

Hence we may want to label X axis in terms of angle, π.

In the terminal, type,

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,) and pressEnter.

To change X ticks to angle, type the following command as shown on the screen.

Here we are using the Greek alphabet pi and setting its position.

Point mouse to ('2{/Symbol p}' and then to 2*pi. This command places, Greek symbol pi, at the value of 3.14.

Label 2π is at position 6.28 on the X axis.

Point to and . Multiples of pi are placed at their respective positions.
Type help set xtics

Press Enter

For more help on the formats of X tics, type the command help space set space xtics.
Press Ctrl C. Press Ctrl and C keys to exit the help section.
Press Ctrl+Shift+K in Debian. I will clear the terminal.
Only narration It is also possible to add multiple functions on the same graph.
Type plot sin (x), cos (x) and press Enter. To plot sin x and cos x on the same graph, separate the functions by a comma.

Type plot space sin x comma cos x Make sure that the angle x, is within parentheses .

Point to the graph window. Notice that the two functions are plotted together now.
Only narration. Next, we will add sin (x) plus cos (x) function to the same graph.
Type plot sin(x), cos(x), sin(x) + cos(x) and press Enter. For this, type plot space sin(x) comma cos(x) comma sin(x) plus cos(x) .
Point to the graph window. Notice that all 3 functions are plotted together on the same graph now.

Next, let’s learn how to get sin(x) data points into a file.

Only narration. To get an ASCII column format output, set table command can be used.
Type set space table and press Enter. First type set space table.
Enter command plot sin(x) and press Enter. Then type plot space sin(x).
Point to the screen An x y column data for sin(x) is generated on the screen.
Highlight first column.

Highlight second column.

The first column is x data and the second column is y data.

They are the points of sin x versus x graph.

Press Ctrl+Alt+K I will clear the terminal.

We can save the output as a text file.

Type set table "table-sinx.txt" and press Enter For this, type set space table space within double quotes sinx dot txt.

Here sinx dot txt is the output filename.

Type plot sin(x) and press Enter. Then, type plot space sin(x).

The output is saved to the file sin x dot txt. The data is not seen on the screen.

Show screenshot of Desktop showing the file sinx.txt. The file is stored in the directory from where we opened gnuplot in the terminal.
Type unset table and press Enter. Type unset space table to exit the tabular output mode.
Enter q Then type quit or q to quit gnuplot.
Slide Number 6

Summary

Let’s summarize.

In this tutorial, we plotted 2D graphs of functions.

We also

  • Added grid and set limits
  • Zoomed in and zoomed out of the graph
  • Added axis labels and graph title
  • Changed font style and size

and

  • Saved the data points to a file


Slide Number 7

Assignment

As an assignment, plot the following functions:
  • tan x
  • x squared and
  • x minus three squared
Completed assignment Your completed assignment should look like this.
Slide Number 8

Spoken Tutorial Project

This video summarises the Spoken Tutorial Project

Please download and watch it.

Slide Number 9

Spoken Tutorial workshops

We conduct workshops using spoken tutorials 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.
This is Rani from IIT, Bombay. Thank you for joining.

Contributors and Content Editors

Madhurig, Ranipv076