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...")
 
Line 1: Line 1:
{|border=1
+
{|border=1  
 +
 
 
|-
 
|-
|| Visual Cue
+
|| '''Visual Cue'''
|| Narration
+
|| '''Narration'''
  
 
|-
 
|-
Line 8: Line 9:
 
'''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 surfaces 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 via script
 +
* Write, edit and execute a script
 
* Draw a sphere
 
* Draw a sphere
* Change surface color of sphere
+
* Change the surface color of the sphere
* Generate heat map
+
* Generate a heat map
  
 
|-
 
|-
 
|| '''Slide Number 4'''
 
|| '''Slide Number 4'''
 
'''System and Software Requirement'''
 
'''System and Software Requirement'''
||
+
||  
* Debian Linux 9.3
+
* '''Ubuntu Linux''' 16.04 OS
* Gedit text editor 3.22.0 and
+
* '''Gedit''' version 3.18and
* 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'''.
 +
The '''splot''' command generates 3D graph in the graphics window.
 +
Make sure '''x''' and '''y''' are in parenthesis.
  
 
|-
 
|-
||  
+
|| Cursor on the graphics window.
|| Make sure x and y are in parenthesis.
+
|| Besides '''x''' and '''y''', the third axis is the value of the function in the plot.
This generates a 3D 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'''.
 +
|| 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 finer mesh defining the surface.
 
|| '''Replot''' to notice a finer mesh defining the surface.
  
 
|-
 
|-
|| Rotate the surface
+
|| Cursor on the graphics window.
|| To rotate, hold down left mouse key and move to your desired viewing angle
+
|| Use the command, '''help space splot''' to know more about the '''splot''' command.
  
 
|-
 
|-
|| Close graph
+
|| Hold down the left mouse key and move the mouse.
|| Notice, the angle change in the top of the graphic window.
+
|| Hold down the left mouse key and move the mouse to rotate the graph.
Next, close the graphic window.
+
We will write a script to draw a sphere in gnuplot using a text editor.
+
  
 
|-
 
|-
|| '''Slide number 6'''
+
|| Cursor on the view angle value, in the graphics window.
'''Polar coordinates and sphere'''
+
Highlight the changed angle in the graphics window during video editing.
|| Equation of a sphere with radius '''R''', centered at x0,y0 and z0 is
+
|| The viewing angle change in the graphic window while rotating the graph.
x square plus y square plus z square plus is equal to R square
+
Here r is the radius of the square
+
Such functions can be plotted in polar co-ordinates.
+
  
 
|-
 
|-
||  
+
|| Close the graphic window.
|| We will practice to write scripts in a text file.
+
|| Next, we will plot a sphere in '''gnuplot'''.
Then run the script file to plot a graph.
+
Close the graphics window.
We can edit the script file to make any required changes in the graph.
+
  
 
|-
 
|-
|| Click on '''Search your computer and online resources'''
+
|| '''Slide number 6'''
|| Click on '''Search your computer and online resources''' icon
+
'''Equation for a sphere'''
 +
This function can be plotted in polar coordinates as,
 +
r.sin(u).cos(v), r.sin(u).sin(v),r.cos(u)
 +
|| Equation of a sphere with radius r, centered at (0,0,0) is shown.
 +
It is, x square plus y square plus z square is equal to r square.
 +
This function can be plotted in polar coordinates as seen here.
  
 
|-
 
|-
|| In search form type''' terminal''' and press enter
+
|| Cursor on the slide.
|| In search form type '''gedit''' and press enter to open '''gedit'''
+
|| We will write a script to draw a sphere in '''gnuplot''' using a text editor.
 +
Then run the script file to plot a graph.
  
 
|-
 
|-
||  
+
|| Press '''Ctrl+Alt+T'''.
|| I will use gedit text editor, windows users may use notepad software.
+
Type '''gedit''' and press '''Enter'''.
 +
|| Open another '''terminal''' and type '''gedit''' to open a '''gedit''' window.
  
 
|-
 
|-
||  
+
|| Cursor on '''Gedit''' text editor.
|| Let's enter a comment on first line.
+
|| '''Windows''' users may use '''notepad''' or '''wordpad''' software.
Comment starts with a '''hash'''.
+
  
 
|-
 
|-
|| '''# my first 3D plot''' and press enter
+
|| Type '''# my first 3D plot''' and press '''Enter'''.
|| I will type '''# my first 3D plot''' and press enter to start to start newline
+
|| 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'''.
  
 
|-
 
|-
 
||  
 
||  
|| Next, please type the commands as seen
+
|| Next, please type the commands as shown here.
  
 
|-
 
|-
|| >''' set parametric'''
+
|| Type '''set parametric''' and press '''Enter'''.
|| First set to parametric mode
+
|| First, set the plot to parametric mode.
  
 
|-
 
|-
|| >'''set angle degree '''
+
|| Type '''set angle degree'''.
|| Then set angle to degree  
+
Press '''Enter'''.
 +
|| Then set the angle to degree .
  
 
|-
 
|-
|| >'''set urange [0:360] '''
+
|| Enter the 2 lines
>'''set vrange [0:360] '''
+
'''set urange [0:360] '''
|| Set u and v range
+
'''set vrange [0:180]'''
 +
and press '''Enter'''.
 +
|| Next, specify the ranges of the parameters '''u''' and '''v'''.
 +
Here we have '''Polar coordinates'''.
  
 
|-
 
|-
|| >'''set isosample 50,50 '''
+
|| Type '''set isosample 50,50''' and press '''Enter'''.
|| Set isosamples to make a fine mesh
+
|| Set '''isosamples''' to make a fine mesh.
  
 
|-
 
|-
|| >'''set ticslevel 0 '''
+
|| Type '''set ticslevel 0''' and press '''Enter'''.
|| Set tic level to zero.
+
|| Set '''ticks''' level to zero.
 +
This sets the '''XY''' plane at zero value of '''Z''' axis.
  
 
|-
 
|-
|| >'''r=1 '''
+
|| Type '''r=1''' and press '''Enter'''.
|| I will set the radius to one.
+
|| I will set the radius of the sphere to one.
  
 
|-
 
|-
|| Highlight
+
|| Type,
'''>splot r*cos(u)*cos(v),r*sin(u)*cos(v),r*sin(v)'''
+
'''splot r*sin(u)*cos(v), r*sin(u)*sin(v),r*cos(u) '''and press '''Enter'''.
|| Next splot the function for sphere
+
|| Next add the line, '''splot space''' and the function for sphere as seen.
Pause the video if necessary, and explore more.
+
  
 
|-
 
|-
|| '''Ctrl s'''
+
|| Press '''Ctrl+S'''.
|| Press '''crtl s''' to save
+
|| Press '''Control S''' to save the file.
  
 
|-
 
|-
|| Give file name '''sphere.dem''' in '''desktop''' folder
+
|| Give file name, '''sphere.dem''' in path '''desktop''' folder.
click on '''save'''
+
Click on '''Save'''.
 
|| A dialogue box opens.  
 
|| A dialogue box opens.  
I will save the file in '''Desktop''' folder with name '''sphere.dem'''
+
I will save the file in '''Desktop''' folder with filename '''sphere.dem'''.
Click on '''Save'''
+
Click on '''Save''' to save the script.
  
 
|-
 
|-
|| Close '''gedit''', go to terminal
+
|| Minimize '''gedit''' and go to '''terminal'''.
|| Minimize gedit.  
+
|| Click on the hyphen sign on the top to minimize the gedit window.
Go back to the '''terminal''' where '''gnuplot''' was open
+
Go back to the gnuplot '''terminal'''.
If you had closed gnuplot, please open gnuplot again
+
  
 
|-
 
|-
|| '''>cd “~/Desktop”'''
+
|| Cursor on '''terminal'''.
|| On gnuplot prompt change directory to '''desktop'''  
+
|| If you had closed '''gnuplot''', please open '''gnuplot''' again.
Use commands as seen on the screen
+
 
Let's run the script to generate a sphere.
 
Let's run the script to generate a sphere.
  
 
|-
 
|-
|| >'''load 'sphere.dem''''
+
|| Enter the command '''load 'sphere.dem' '''.
|| Type '''load space within single quotes sphere.dem'''
+
|| Enter the command, '''load space within single quotes sphere dot dem'''.
  
 
|-
 
|-
||  
+
|| Point to the sphere in graphics window.
|| A plot of a sphere centered at zero, zero, zero with radius one appear on the screen
+
|| A sphere, centered at zero, zero, zero with radius one appears on the screen.
Next, say I want to change the sphere to blue color
+
  
 
|-
 
|-
|| Go back to '''gedit''' script
+
|| Rotate the sphere.
|| Go back to the '''gedit''' window to edit the script.
+
|| Let’s change the color of the sphere to blue.
If you had closed it, please open the script file to edit.
+
We will edit the script file to make the required changes.
  
 
|-
 
|-
|| Add '''lc rgb 'red'''' in the end of splot command
+
|| Go to the '''gedit''' script .
|| Add '''lc space rgb space within single quotes blue'''
+
|| Go to the '''gedit''' window to edit the script.
 +
If you had closed it, please open the '''script''' file to edit.
  
 
|-
 
|-
|| Save file
+
|| Add '''lc rgb 'blue'''' in the end of the splot command.
|| Save the changes in the script file
+
|| Add '''lc space rgb space''' within single quotes '''blue''' .
 +
This is part of the splot command line.
  
 
|-
 
|-
|| Go to gnuplot window
+
|| Press '''Ctrl+S '''.
|| Come back to gnuplot and load the script file again as before
+
|| Save the changes in the '''script''' file.
  
 
|-
 
|-
|| >'''load 'sphere.dem''''
+
|| Come back to '''gnuplot '''.
Next, let's try a heatmap with pm3d command
+
|| Come back to the terminal with the '''gnuplot''' prompt.
 +
Load the edited script file again.
  
 
|-
 
|-
|| Highlight and delete,
+
|| Type '''load 'sphere.dem'''' and press '''Enter'''.
'''lc rgb blue'''
+
|| Enter the command '''load space within single quotes sphere.dem'''.
|| Go back to the script in gedit
+
In some systems, pressing the up arrow key scrolls through the command history.
Delete the '''lc space rgb space blue''' part
+
This specified blue color as we saw in the graph
+
  
 
|-
 
|-
|| Type''' with pm3d'''
+
|| Cursor on the graphics window.
|| Instead type in '''with space pm3d''' to generate surface with heatmap
+
|| Next, let's make a '''heatmap''' with '''pm3d''' command.
  
 
|-
 
|-
|| Save '''script''', minimize '''edit''', go to '''gnuplot'''
+
|| Select and delete the part,
| | Save the '''script''' file, minimize '''gedit''' and go to '''gnuplot'''
+
'''lc rgb blue''' .
 +
|| Go back to the script in '''gedit''' to make changes in it.
 +
Delete the '''lc space rgb space blue''' command.
  
 
|-
 
|-
|| Highlight,
+
|| Type''' with pm3d''' at the end of the same line.
>'''load 'sphere.dem''''
+
|| Add, '''with space pm3d''' at the end of the line, as seen on the screen.
|| Load the '''sphere.dem''' script again
+
  
 
|-
 
|-
|| Hover mouse on heat map guide
+
|| Press '''Ctrl+S''', minimize '''gedit''' and go to '''gnuplot'''.
|| Notice the '''heatmap''' in the sphere
+
|| Save the '''script''' file, minimize '''gedit''' and go to '''gnuplot'''.
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.
+
  
 
|-
 
|-
||  
+
|| Enter command '''load 'sphere.dem' '''.
|| Via scripts, we can generate and make changes to graphs easily.
+
|| 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.
 +
|| It is called a '''colorbox''' in '''gnuplot'''.
 +
The values between 1 to 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 '''terminal'''.
|| Pause the video if required.
+
|| Practice and familiarize with commands and styles.
Practice and familiarize with commands and styles.
+
Learners can also use the help command for this purpose.
  
 
|-
 
|-
 
|| '''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 plot 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
+
|| * Plotted a sphere and changed the color
* Wrote and modified script, ran the script to generate plot<br/>and
+
* Wrote and modified a script
* Learned to generate heat map
+
* Executed the script to generate a plot
 +
* Learned to generate a heat map
  
 
|-
 
|-
Line 295: Line 324:
 
'''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 5 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'''
+
Equation for a sphere centered at (x1,y1,z1) in polar coordinates is shown here.
If sphere is centered at x1, y1,z1  
+
x1+r.sin(u).cos(v), y1+r.sin(u).sin(v), z1+r.cos(u)
equation takes the form as seen on the slide
+
|| Hint: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'''
 
'''Acknowledgement'''
|| Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
+
|| '''Spoken Tutorial Project''' is funded by '''NMEICT''', '''MHRD''', '''Government of India'''.
  
 
|-
 
|-
 
||  
 
||  
|| Thank you for joining.
+
|| This is Rani from IIT Bombay.
 +
Thank you for joining.
 +
 
 
|-
 
|-
 
|}
 
|}

Revision as of 11:34, 6 December 2019

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 surfaces differently
Slide Number 3

Learning Objectives

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

System and Software Requirement

  • Ubuntu Linux 16.04 OS
  • Gedit version 3.18and
  • 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.

The splot command generates 3D graph in the graphics window. Make sure x and y are in parenthesis.

Cursor on 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 finer 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 change in the graphic window while rotating the graph.
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 polar coordinates as, r.sin(u).cos(v), r.sin(u).sin(v),r.cos(u)

Equation of a sphere with radius r, centered at (0,0,0) is shown.

It is, x square plus y square plus z square is equal to r square. This function can be plotted in polar coordinates as seen here.

Cursor on the slide. We will write a script to draw a sphere in gnuplot using a 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.

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 the parameters u and v.

Here we have Polar coordinates.

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 dialogue 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 gnuplot terminal.

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 gedit 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 .

This is part of the splot command line.

Press Ctrl+S . Save the changes in the script file.
Come back to gnuplot . Come back to the terminal with the gnuplot prompt.

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.

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 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. It is called a colorbox in gnuplot.

The values between 1 to 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 terminal. Practice and familiarize with commands and styles.

Learners can also use the help command for this purpose.

Slide Number 7

Summary

To summarize, in this tutorial, we,
  • Generated a 3D plot 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
  • Learned to generate a heat map
Slide Number 9

Assignment

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

Assignment Equation for a sphere centered at (x1,y1,z1) in polar coordinates is shown here. x1+r.sin(u).cos(v), y1+r.sin(u).sin(v), z1+r.cos(u)

Hint: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

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, PoojaMoolya, Ranipv076, Snehalathak