Difference between revisions of "Gnuplot/C2/Generate-3D-plots-and-surfaces/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "{|border=1 |- || Visual Cue || Narration |- || '''Slide Number 1''' '''Title Slide ''' '''Generate 3D plot and surfaces''' || Welcome to the tutorial on '''Generate 3D plot a...")
 
 
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{|border=1
+
{|border=1  
 +
 
 
|-
 
|-
|| Visual Cue
+
|| '''Visual Cue'''
|| Narration
+
|| '''Narration'''
  
 
|-
 
|-
 
|| '''Slide Number 1'''
 
|| '''Slide Number 1'''
 
'''Title Slide '''
 
'''Title Slide '''
 +
 
'''Generate 3D plot and surfaces'''
 
'''Generate 3D plot and surfaces'''
|| Welcome to the tutorial on '''Generate 3D plot and surfaces'''
+
|| Welcome to the tutorial on '''Generate 3D plot and Surfaces'''.
  
 
|-
 
|-
 
|| '''Slide Number 2'''
 
|| '''Slide Number 2'''
 
'''Learning Objectives'''
 
'''Learning Objectives'''
|| In this tutorial we will learn,
+
|| In this tutorial we will learn to,
*Generate 3D plot with splot command
+
* Generate a 3D plot with '''splot''' command
* Format surface properties
+
* Rotate to change the viewing angle
* Change viewing angle and rotate view
+
* Change the surface properties
* Color the two sides of surfaces differently
+
* Color the two sides of the surface differently
  
 
|-
 
|-
 
|| '''Slide Number 3'''
 
|| '''Slide Number 3'''
 
'''Learning Objectives'''
 
'''Learning Objectives'''
|| * Make graph via script
+
||  
* Run and edit script to change graph
+
* Make a graph using script commands
 +
* Write, edit and execute a script
 
* Draw a sphere
 
* Draw a sphere
* Change surface color of sphere
+
* Change the surface color of the sphere and
* Generate heat map
+
* Generate a heat map
  
 
|-
 
|-
 
|| '''Slide Number 4'''
 
|| '''Slide Number 4'''
'''System and Software Requirement'''
+
'''System Requirement'''
||
+
||  
* Debian Linux 9.3
+
* '''Ubuntu Linux''' 16.04 OS
* Gedit text editor 3.22.0 and
+
* '''Gedit''' version 3.18 and  
* gnuplot 5.2.5
+
* '''gnuplot''' version 5.2.6
  
 
|-
 
|-
 
|| '''Slide Number 5'''
 
|| '''Slide Number 5'''
 
'''Pre-requisites'''
 
'''Pre-requisites'''
|| To follow this tutorial, learners must be familiar with,
+
 
* Basic computer and internet skills
+
'''https://spoken-tutorial.org'''
* Concept of graphing and
+
|| To follow this tutorial,  
* College level Mathematics skills
+
 
 +
* Learner must be familiar with basics of '''gnuplot'''.
 +
* For pre-requisite '''gnuplot''' tutorials, please visit this site.
  
 
|-
 
|-
|| ctrl+alt+T
+
|| Press '''Ctrl+Alt+T'''.
>'''gnuplot'''
+
|| Open a terminal.
|| Please open a terminal by pressing control alt t keys together
+
A terminal opens
+
Please open gnuplot from the terminal
+
Type gnuplot in prompt to open gnuplot
+
  
 
|-
 
|-
|| '''clear screen'''
+
|| Type '''cd Desktop''' and press '''Enter'''.
|| I will also clear the screen for clarity in video.
+
|| Change the directory to '''Desktop'''.
  
 
|-
 
|-
||  
+
|| Type '''gnuplot''' and press '''Enter'''.
|| We will plot the function, cos x cos y to form a surface.
+
|| I will open '''gnuplot''' from '''Desktop''' directory in the '''terminal'''.
Besides x and y axes, the third axis is the value of the function in the plot.
+
  
 
|-
 
|-
||  
+
|| Press '''Ctrl+L'''.
|| Command for 3D plot is splot
+
|| I will also clear the screen.
 +
 
 +
We will plot the function, '''cos x cos y''' to draw a surface.
 +
 
  
 
|-
 
|-
|| '''splot cos(x)*cos(y)'''
+
|| Type '''splot cos(x)*cos(y)''' and press '''Enter'''.
|| Hence, we will enter command '''splot space cos x times cos y'''
+
|| Enter the command '''splot space cos x times cos y'''.
 +
 
 +
Make sure '''x''' and '''y''' are in parenthesis.
 +
 
  
 
|-
 
|-
||  
+
|| Cursor on the graphics window.
|| Make sure x and y are in parenthesis.
+
|| The '''splot''' command generates 3D graph in the graphics window.
This generates a 3D plot.
+
 
 +
Besides '''x''' and '''y''', the third axis is the value of the function in the plot.
  
 
|-
 
|-
|| Rotate the graph
+
|| Hold down left mouse key and turn around and rotate the plot.
|| Hold down left mouse key and turn around and rotate the plot to your desire.
+
|| Hold down the left mouse key.
 +
 
 +
Move the mouse to rotate the graph and change the viewing angle.
  
 
|-
 
|-
|| '''Zoom into graph'''
+
|| Zoom into the graph.
|| Zoom in slightly into graph to see a wavy surface.
+
|| Zoom in slightly into the graph to see a wavy surface.
 +
 
 
Notice the surface is plotted in a wide mesh style.
 
Notice the surface is plotted in a wide mesh style.
  
 
|-
 
|-
||  
+
|| Cursor on the graphics window.
|| Let's change some of the surface and graph properties.
+
|| Let's change some of the properties of the surface.
Next, we will color both sides of the surface differently.
+
  
 
|-
 
|-
|| >'''set hidden3d'''
+
|| Hover mouse over the two sides of the surface.
>'''replot'''
+
|| We will color both sides of the surface differently.
|| The required command for this is '''set space hidden3d'''
+
Let's type it.
+
Replot to see the changed colors.
+
  
 
|-
 
|-
||  
+
|| Enter the command '''set hidden3d '''.
|| Now notice the hidden surface is colored green and the top surface is purple.
+
 
 +
Enter the command '''replot'''.
 +
|| The required command for this is '''set space hidden3d''' .
 +
 
 +
Enter the command '''replot''', to see the changed colors.
  
 
|-
 
|-
|| >'''set isosamples 50,50'''
+
|| Show the two colors on the screen.
|| Enter command, '''set space isosamples space 50 comma 50'''
+
|| Notice the hidden surface is colored green and the top surface is purple.
  
 
|-
 
|-
|| >'''replot'''
+
|| Type '''set isosamples 50,50 '''and press '''Enter'''.
|| '''Replot''' to notice a finer mesh defining the surface.
+
|| Let’s divide the surface into a fine grid.
 +
 
 +
Enter the command, '''set space isosamples space 50 comma 50'''.
  
 
|-
 
|-
|| Rotate the surface
+
|| Type '''replot''' and press '''Enter'''.
|| To rotate, hold down left mouse key and move to your desired viewing angle
+
|| '''Replot''' to notice a fine mesh defining the surface.
  
 
|-
 
|-
|| Close graph
+
|| Cursor on the graphics window.
|| Notice, the angle change in the top of the graphic window.
+
|| Use the command, '''help space splot''' to know more about the '''splot''' command.
Next, close the graphic window.
+
 
We will write a script to draw a sphere in gnuplot using a text editor.
+
|-
 +
|| Hold down the left mouse key and move the mouse.
 +
|| Hold down the left mouse key and move the mouse to rotate the graph.
 +
 
 +
|-
 +
|| Cursor on the view angle value, in the graphics window.
 +
 
 +
Highlight the changed angle in the graphics window during video editing.
 +
|| The viewing angle changes in the graphic window while rotating the graph.
 +
 
 +
|-
 +
|| Click on Close button to close the graphic window.
 +
|| Next, we will plot a sphere in '''gnuplot'''.
 +
 
 +
Close the graphics window.
  
 
|-
 
|-
 
|| '''Slide number 6'''
 
|| '''Slide number 6'''
'''Polar coordinates and sphere'''
+
'''Equation for a Sphere'''
|| Equation of a sphere with radius '''R''', centered at x0,y0 and z0 is
+
 
x square plus y square plus z square plus is equal to R square
+
 
Here r is the radius of the square
+
This function can be plotted in parametric mode as,
Such functions can be plotted in polar co-ordinates.
+
r.sin(u).cos(v), r.sin(u).sin(v),r.cos(u)
 +
|| Equation for a sphere with radius r, centered at x0, y0, and z0 is shown here.
 +
 
 +
It is, x square plus y square plus z square is equal to r square.
 +
 
 +
This function can be plotted in parametric mode as seen here.
  
 
|-
 
|-
||  
+
|| Cursor on the slide.
|| We will practice to write scripts in a text file.
+
|| We will write a script to draw a sphere in '''gnuplot''' using the text editor.
 +
 
 
Then run the script file to plot a graph.
 
Then run the script file to plot a graph.
We can edit the script file to make any required changes in the graph.
 
  
 
|-
 
|-
|| Click on '''Search your computer and online resources'''
+
|| Press '''Ctrl+Alt+T'''.
|| Click on '''Search your computer and online resources''' icon
+
Type '''gedit''' and press '''Enter'''.
 +
|| Open another '''terminal''' and type '''gedit''' to open a '''gedit''' window.
  
 
|-
 
|-
|| In search form type''' terminal''' and press enter
+
|| Cursor on '''Gedit''' text editor.
|| In search form type '''gedit''' and press enter to open '''gedit'''
+
|| '''Windows''' users may use '''notepad''' or '''wordpad''' software.
  
 
|-
 
|-
||  
+
|| Type '''# my first 3D plot''' and press '''Enter'''.
|| I will use gedit text editor, windows users may use notepad software.
+
|| Let's enter a comment on the first line.
 +
 
 +
I will type '''hash my first 3D plot''' and press '''Enter''' to start a newline.
 +
 
 +
The comments start with a '''hash'''.
  
 
|-
 
|-
||  
+
||Type the commands in the text editor.
|| Let's enter a comment on first line.
+
|| Next, please type the commands as shown here.
Comment starts with a '''hash'''.
+
  
 
|-
 
|-
|| '''# my first 3D plot''' and press enter
+
|| Type '''set parametric''' and press '''Enter'''.
|| I will type '''# my first 3D plot''' and press enter to start to start newline
+
|| First, set the plot to parametric mode.
  
 
|-
 
|-
||  
+
|| Type '''set angle degree'''.
|| Next, please type the commands as seen
+
Press '''Enter'''.
 +
|| Then set the angle to degree .
  
 
|-
 
|-
|| >''' set parametric'''
+
|| Enter the 2 lines
|| First set to parametric mode
+
 
 +
'''set urange [0:360] '''
 +
 
 +
'''set vrange [0:180]'''
 +
 
 +
and press '''Enter'''.
 +
|| Next, specify the ranges of parameters '''u''' and '''v'''.
  
 
|-
 
|-
|| >'''set angle degree '''
+
|| Type '''set isosample 50,50''' and press '''Enter'''.
|| Then set angle to degree
+
|| Set '''isosamples''' to make a fine mesh.
  
 
|-
 
|-
|| >'''set urange [0:360] '''
+
|| Type '''set ticslevel 0''' and press '''Enter'''.
>'''set vrange [0:360] '''
+
|| Set '''ticks''' level to zero.
|| Set u and v range
+
 
 +
This sets the '''XY''' plane at zero value of '''Z''' axis.
  
 
|-
 
|-
|| >'''set isosample 50,50 '''
+
|| Type '''r=1''' and press '''Enter'''.
|| Set isosamples to make a fine mesh
+
|| I will set the radius of the sphere to one.
  
 
|-
 
|-
|| >'''set ticslevel 0 '''
+
|| Type,
|| Set tic level to zero.
+
'''splot r*sin(u)*cos(v), r*sin(u)*sin(v),r*cos(u) '''and press '''Enter'''.
 +
|| Next add the line, '''splot space''' and the function for sphere as seen.
  
 
|-
 
|-
|| >'''r=1 '''
+
|| Press '''Ctrl+ S'''.
|| I will set the radius to one.
+
|| Press '''Control S''' to save the file.
  
 
|-
 
|-
|| Highlight
+
|| Give file name, '''sphere.dem''' in path '''desktop''' folder.
'''>splot r*cos(u)*cos(v),r*sin(u)*cos(v),r*sin(v)'''
+
Click on '''Save'''.
|| Next splot the function for sphere
+
|| A dialog box opens.
Pause the video if necessary, and explore more.
+
 
 +
I will save the file in '''Desktop''' folder with filename '''sphere.dem'''.
 +
 
 +
Click on '''Save''' to save the script.
  
 
|-
 
|-
|| '''Ctrl s'''
+
|| Minimize '''gedit''' and go to '''terminal'''.
|| Press '''crtl s''' to save
+
|| Click on the hyphen sign on the top to minimize the gedit window.
 +
 
 +
Go back to the '''terminal''', where '''gnuplot''' is open.
  
 
|-
 
|-
|| Give file name – '''sphere.dem''' in '''desktop''' folder
+
|| Cursor on '''terminal'''.
click on '''save'''
+
|| If you had closed '''gnuplot''', please open '''gnuplot''' again.
|| A dialogue box opens.
+
 
I will save the file in '''Desktop''' folder with name '''sphere.dem'''
+
Let's run the script to generate a sphere.
Click on '''Save'''
+
  
 
|-
 
|-
|| Close '''gedit''', go to terminal
+
|| Enter the command '''load 'sphere.dem' '''.
|| Minimize gedit.
+
|| Enter the command, '''load''' space within single quotes '''sphere dot dem'''.
Go back to the '''terminal''' where '''gnuplot''' was open
+
If you had closed gnuplot, please open gnuplot again
+
  
 
|-
 
|-
|| '''>cd “~/Desktop”'''
+
|| Point to the sphere in graphics window.
|| On gnuplot prompt change directory to '''desktop'''
+
|| A sphere, centered at zero, zero, zero with radius one appears on the screen.
Use commands as seen on the screen
+
Let's run the script to generate a sphere.
+
  
 
|-
 
|-
|| >'''load 'sphere.dem''''
+
|| Rotate the sphere.
|| Type '''load space within single quotes sphere.dem'''
+
|| Let’s change the color of the sphere to blue.
 +
 
 +
We will edit the script file to make the required changes.
  
 
|-
 
|-
||  
+
|| Go to the '''gedit''' script .
|| A plot of a sphere centered at zero, zero, zero with radius one appear on the screen
+
|| Go to the edit window to edit the script.
Next, say I want to change the sphere to blue color
+
 
 +
If you had closed it, please open the '''script''' file to edit.
  
 
|-
 
|-
|| Go back to '''gedit''' script
+
|| Add '''lc rgb 'blue'''' in the end of the splot command.
|| Go back to the '''gedit''' window to edit the script.
+
|| Add '''lc space rgb space''' within single quotes '''blue'''.
If you had closed it, please open the script file to edit.
+
 
  
 
|-
 
|-
|| Add '''lc rgb 'red'''' in the end of splot command
+
|| Press '''Ctrl+S '''.
|| Add '''lc space rgb space within single quotes blue'''
+
|| Save the changes in the '''script''' file.
  
 
|-
 
|-
|| Save file
+
|| Come back to '''gnuplot '''.
|| Save the changes in the script file
+
|| Come back to the '''gnuplot''' prompt and load the edited script file again.
  
 
|-
 
|-
|| Go to gnuplot window
+
|| Type '''load 'sphere.dem'''' and press '''Enter'''.
|| Come back to gnuplot and load the script file again as before
+
|| Enter the command '''load''' space within single quotes '''sphere.dem'''.
 +
 
 +
In some systems, pressing the up arrow key scrolls through the command history.
  
 
|-
 
|-
|| >'''load 'sphere.dem''''
+
|| Show the blue sphere.
Next, let's try a heatmap with pm3d command
+
|| Notice the blue sphere in the graphics window.
  
 
|-
 
|-
|| Highlight and delete,
+
|| Cursor on the graphics window.
'''lc rgb blue'''
+
|| Next, let's make a '''heatmap''' with '''pm3d''' command.
|| Go back to the script in gedit
+
Delete the '''lc space rgb space blue''' part
+
This specified blue color as we saw in the graph
+
  
 
|-
 
|-
|| Type''' with pm3d'''
+
|| Select and delete the part,
|| Instead type in '''with space pm3d''' to generate surface with heatmap
+
'''lc rgb blue''' .
 +
|| Go back to the script in '''gedit''' to make changes in it.
 +
 
 +
Delete the '''lc space rgb space blue''' in the splot command.
  
 
|-
 
|-
|| Save '''script''', minimize '''edit''', go to '''gnuplot'''
+
|| Type''' with pm3d''' at the end of the same line.
| | Save the '''script''' file, minimize '''gedit''' and go to '''gnuplot'''
+
|| Add, '''with space pm3d''' at the end of the line, as seen on the screen.
  
 
|-
 
|-
|| Highlight,
+
|| Press '''Ctrl+S''', minimize '''gedit''' and go to '''gnuplot'''.
>'''load 'sphere.dem''''
+
|| Save the '''script''' file, minimize '''gedit''' and go to '''gnuplot'''.
|| Load the '''sphere.dem''' script again
+
  
 
|-
 
|-
|| Hover mouse on heat map guide
+
|| Enter command '''load 'sphere.dem' '''.
|| Notice the '''heatmap''' in the sphere
+
|| Load the '''sphere.dem''' script again.
Notice the color ranges and the map guide is also visible
+
Values in range 1 to 0.8 are yellow and minus 0.8 to minus 1 is deep purple.
+
  
 
|-
 
|-
||  
+
|| Point mouse next to the map guide in graphics window.
|| Via scripts, we can generate and make changes to graphs easily.
+
|| Notice the '''heatmap''' in the sphere.
 +
 
 +
The color scale bar for the color gradient, is visible on the side.
 +
 
 +
|-
 +
|| Hover mouse on the range guide range.
 +
|| This is called a '''colorbox''' in '''gnuplot'''.
 +
 
 +
The values between 1 and 0.8 are colored in yellow.
 +
 
 +
Values between minus 0.8 to minus 1 are colored in deep purple.
 +
 
 +
|-
 +
|| Cursor on the graphics window.
 +
|| Using scripts, we can generate and make changes in the graph.
 +
 
 +
|-
 +
|| Exit '''gnuplot''' and '''gedit'''.
 +
|| Let’s exit '''gnuplot''' and '''gedit'''.
 +
 
 
Similar scripts are available in '''gnuplot''' demo website.
 
Similar scripts are available in '''gnuplot''' demo website.
 +
 
|-
 
|-
||  
+
|| Cursor on the '''terminal'''.
|| Pause the video if required.
+
|| Practise and familiarize with commands and styles.
Practice and familiarize with commands and styles.
+
 
 +
Learners can also use the help command for this purpose.
 +
 
 +
|-
 +
|| Type '''q''' to quit '''gnuplot''' and close '''gedit'''.
 +
||Let's exit '''gnuplot''' and '''gedit'''.
  
 
|-
 
|-
 
|| '''Slide Number 7'''
 
|| '''Slide Number 7'''
 
'''Summary'''
 
'''Summary'''
|| To summarize, in this tutorial, we learned to
+
|| To summarize, in this tutorial, we,
* Generated 3D graph with splot command
+
* Generated a 3D surface with the '''splot''' command
* Formatted 3D plot
+
* Changed the viewing angle
* Changed viewing angle and rotate view
+
* Modified the 3D plot
* Colored 2 surfaces of plot differently
+
* Colored the two surfaces of the plot differently
  
 
|-
 
|-
 
|| '''Slide Number 8'''
 
|| '''Slide Number 8'''
 
'''Summary'''
 
'''Summary'''
|| * Plotted a sphere and formatted color
+
||  
* Wrote and modified script, ran the script to generate plot<br/>and
+
* Plotted a sphere and changed the color
* Learned to generate heat map
+
* Wrote and modified a script
 +
* Executed the script to generate a plot and  
 +
* Learned to generate a heat map
  
 
|-
 
|-
Line 295: Line 368:
 
'''Assignment'''
 
'''Assignment'''
 
|| For assignment, plot the following,
 
|| For assignment, plot the following,
Plot 5 spheres in the graph with radius 0.5, 1, 2, 3 and 4
+
* Plot five spheres in a graph with different radius.
Center them differently  
+
* Center and color the spheres differently.
Hint: To plot more than one function, separate them using '''comma''' sign
+
  
 
|-
 
|-
 
|| '''Slide Number 10'''
 
|| '''Slide Number 10'''
 
'''Assignment'''
 
'''Assignment'''
|| If you like to program, you may use a '''for loop'''
+
 
If sphere is centered at x1, y1,z1  
+
Hint:
equation takes the form as seen on the slide
+
For a sphere centered at (x1,y1,z1), use the equation for sphere as seen here.
 +
 
 +
x1+r.sin(u).cos(v), y1+r.sin(u).sin(v), z1+r.cos(u)
 +
|| For a sphere centered at (x1,y1,z1), use the equation for sphere as seen here.
 +
 
 +
|-
 +
|| Show assignment screenshot.
 +
|| Your completed assignment look similar to this.
  
 
|-
 
|-
 
|| '''Slide Number 11'''
 
|| '''Slide Number 11'''
 
'''Spoken Tutorial Project'''
 
'''Spoken Tutorial Project'''
||This video summarises the Spoken Tutorial Project
+
|| This video summarises the '''Spoken Tutorial Project'''.
 +
 
 
Please download and watch it.
 
Please download and watch it.
  
 
|-
 
|-
 
|| '''Slide Number 12'''
 
|| '''Slide Number 12'''
'''Spoken Tutorial workshops'''*
+
'''Spoken Tutorial workshops'''
|| We conduct workshops and give certificates.
+
|| We conduct workshops and give certificates.  
Please write to us.
+
 
 +
For more details, please write to us.
  
 
|-
 
|-
 
|| '''Slide Number 13'''
 
|| '''Slide Number 13'''
'''Forum for specific questions:'''
+
'''Forum for Specific Questions:'''
|| Post your timed queries in the forum.
+
|| Post your timed queries in the '''forum'''.
  
 
|-
 
|-
 
|| '''Slide Number 14'''
 
|| '''Slide Number 14'''
'''Acknowledgement'''
+
'''Acknowledgements'''
|| Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
+
|| '''Spoken Tutorial Project''' is funded by '''MHRD''', '''Government of India'''.
  
 
|-
 
|-
 
||  
 
||  
|| Thank you for joining.
+
|| This is Rani from IIT Bombay.
 +
 
 +
Thank you for joining.
 +
 
 
|-
 
|-
 
|}
 
|}

Latest revision as of 16:07, 28 October 2020

Visual Cue Narration
Slide Number 1

Title Slide

Generate 3D plot and surfaces

Welcome to the tutorial on Generate 3D plot and Surfaces.
Slide Number 2

Learning Objectives

In this tutorial we will learn to,
  • Generate a 3D plot with splot command
  • Rotate to change the viewing angle
  • Change the surface properties
  • Color the two sides of the surface differently
Slide Number 3

Learning Objectives

  • Make a graph using script commands
  • Write, edit and execute a script
  • Draw a sphere
  • Change the surface color of the sphere and
  • Generate a heat map
Slide Number 4

System Requirement

  • Ubuntu Linux 16.04 OS
  • Gedit version 3.18 and
  • gnuplot version 5.2.6
Slide Number 5

Pre-requisites

https://spoken-tutorial.org

To follow this tutorial,
  • Learner must be familiar with basics of gnuplot.
  • For pre-requisite gnuplot tutorials, please visit this site.
Press Ctrl+Alt+T. Open a terminal.
Type cd Desktop and press Enter. Change the directory to Desktop.
Type gnuplot and press Enter. I will open gnuplot from Desktop directory in the terminal.
Press Ctrl+L. I will also clear the screen.

We will plot the function, cos x cos y to draw a surface.


Type splot cos(x)*cos(y) and press Enter. Enter the command splot space cos x times cos y.

Make sure x and y are in parenthesis.


Cursor on the graphics window. The splot command generates 3D graph in the graphics window.

Besides x and y, the third axis is the value of the function in the plot.

Hold down left mouse key and turn around and rotate the plot. Hold down the left mouse key.

Move the mouse to rotate the graph and change the viewing angle.

Zoom into the graph. Zoom in slightly into the graph to see a wavy surface.

Notice the surface is plotted in a wide mesh style.

Cursor on the graphics window. Let's change some of the properties of the surface.
Hover mouse over the two sides of the surface. We will color both sides of the surface differently.
Enter the command set hidden3d .

Enter the command replot.

The required command for this is set space hidden3d .

Enter the command replot, to see the changed colors.

Show the two colors on the screen. Notice the hidden surface is colored green and the top surface is purple.
Type set isosamples 50,50 and press Enter. Let’s divide the surface into a fine grid.

Enter the command, set space isosamples space 50 comma 50.

Type replot and press Enter. Replot to notice a fine mesh defining the surface.
Cursor on the graphics window. Use the command, help space splot to know more about the splot command.
Hold down the left mouse key and move the mouse. Hold down the left mouse key and move the mouse to rotate the graph.
Cursor on the view angle value, in the graphics window.

Highlight the changed angle in the graphics window during video editing.

The viewing angle changes in the graphic window while rotating the graph.
Click on Close button to close the graphic window. Next, we will plot a sphere in gnuplot.

Close the graphics window.

Slide number 6

Equation for a Sphere


This function can be plotted in parametric mode as, r.sin(u).cos(v), r.sin(u).sin(v),r.cos(u)

Equation for a sphere with radius r, centered at x0, y0, and z0 is shown here.

It is, x square plus y square plus z square is equal to r square.

This function can be plotted in parametric mode as seen here.

Cursor on the slide. We will write a script to draw a sphere in gnuplot using the text editor.

Then run the script file to plot a graph.

Press Ctrl+Alt+T.

Type gedit and press Enter.

Open another terminal and type gedit to open a gedit window.
Cursor on Gedit text editor. Windows users may use notepad or wordpad software.
Type # my first 3D plot and press Enter. Let's enter a comment on the first line.

I will type hash my first 3D plot and press Enter to start a newline.

The comments start with a hash.

Type the commands in the text editor. Next, please type the commands as shown here.
Type set parametric and press Enter. First, set the plot to parametric mode.
Type set angle degree.

Press Enter.

Then set the angle to degree .
Enter the 2 lines

set urange [0:360]

set vrange [0:180]

and press Enter.

Next, specify the ranges of parameters u and v.
Type set isosample 50,50 and press Enter. Set isosamples to make a fine mesh.
Type set ticslevel 0 and press Enter. Set ticks level to zero.

This sets the XY plane at zero value of Z axis.

Type r=1 and press Enter. I will set the radius of the sphere to one.
Type,

splot r*sin(u)*cos(v), r*sin(u)*sin(v),r*cos(u) and press Enter.

Next add the line, splot space and the function for sphere as seen.
Press Ctrl+ S. Press Control S to save the file.
Give file name, sphere.dem in path desktop folder.

Click on Save.

A dialog box opens.

I will save the file in Desktop folder with filename sphere.dem.

Click on Save to save the script.

Minimize gedit and go to terminal. Click on the hyphen sign on the top to minimize the gedit window.

Go back to the terminal, where gnuplot is open.

Cursor on terminal. If you had closed gnuplot, please open gnuplot again.

Let's run the script to generate a sphere.

Enter the command load 'sphere.dem' . Enter the command, load space within single quotes sphere dot dem.
Point to the sphere in graphics window. A sphere, centered at zero, zero, zero with radius one appears on the screen.
Rotate the sphere. Let’s change the color of the sphere to blue.

We will edit the script file to make the required changes.

Go to the gedit script . Go to the edit window to edit the script.

If you had closed it, please open the script file to edit.

Add lc rgb 'blue' in the end of the splot command. Add lc space rgb space within single quotes blue.


Press Ctrl+S . Save the changes in the script file.
Come back to gnuplot . Come back to the gnuplot prompt and load the edited script file again.
Type load 'sphere.dem' and press Enter. Enter the command load space within single quotes sphere.dem.

In some systems, pressing the up arrow key scrolls through the command history.

Show the blue sphere. Notice the blue sphere in the graphics window.
Cursor on the graphics window. Next, let's make a heatmap with pm3d command.
Select and delete the part,

lc rgb blue .

Go back to the script in gedit to make changes in it.

Delete the lc space rgb space blue in the splot command.

Type with pm3d at the end of the same line. Add, with space pm3d at the end of the line, as seen on the screen.
Press Ctrl+S, minimize gedit and go to gnuplot. Save the script file, minimize gedit and go to gnuplot.
Enter command load 'sphere.dem' . Load the sphere.dem script again.
Point mouse next to the map guide in graphics window. Notice the heatmap in the sphere.

The color scale bar for the color gradient, is visible on the side.

Hover mouse on the range guide range. This is called a colorbox in gnuplot.

The values between 1 and 0.8 are colored in yellow.

Values between minus 0.8 to minus 1 are colored in deep purple.

Cursor on the graphics window. Using scripts, we can generate and make changes in the graph.
Exit gnuplot and gedit. Let’s exit gnuplot and gedit.

Similar scripts are available in gnuplot demo website.

Cursor on the terminal. Practise and familiarize with commands and styles.

Learners can also use the help command for this purpose.

Type q to quit gnuplot and close gedit. Let's exit gnuplot and gedit.
Slide Number 7

Summary

To summarize, in this tutorial, we,
  • Generated a 3D surface with the splot command
  • Changed the viewing angle
  • Modified the 3D plot
  • Colored the two surfaces of the plot differently
Slide Number 8

Summary

  • Plotted a sphere and changed the color
  • Wrote and modified a script
  • Executed the script to generate a plot and
  • Learned to generate a heat map
Slide Number 9

Assignment

For assignment, plot the following,
  • Plot five spheres in a graph with different radius.
  • Center and color the spheres differently.
Slide Number 10

Assignment

Hint: For a sphere centered at (x1,y1,z1), use the equation for sphere as seen here.

x1+r.sin(u).cos(v), y1+r.sin(u).sin(v), z1+r.cos(u)

For a sphere centered at (x1,y1,z1), use the equation for sphere as seen here.
Show assignment screenshot. Your completed assignment look similar to this.
Slide Number 11

Spoken Tutorial Project

This video summarises the Spoken Tutorial Project.

Please download and watch it.

Slide Number 12

Spoken Tutorial workshops

We conduct workshops and give certificates.

For more details, please write to us.

Slide Number 13

Forum for Specific Questions:

Post your timed queries in the forum.
Slide Number 14

Acknowledgements

Spoken Tutorial Project is funded by MHRD, Government of India.
This is Rani from IIT Bombay.

Thank you for joining.

Contributors and Content Editors

Madhurig, PoojaMoolya, Ranipv076, Snehalathak