Gnuplot/C2/Generate-3D-plots-and-surfaces/English
| 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,
|
| Slide Number 3
Learning Objectives |
* Make graph via script
|
| Slide Number 4
System and Software Requirement |
|
| Slide Number 5
Pre-requisites |
To follow this tutorial, learners must be familiar with,
|
| ctrl+alt+T
>gnuplot |
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 | I will also clear the screen for clarity in video. |
| We will plot the function, cos x cos y to form a surface.
Besides x and y axes, the third axis is the value of the function in the plot. | |
| Command for 3D plot is splot | |
| splot cos(x)*cos(y) | Hence, we will enter command splot space cos x times cos y |
| Make sure x and y are in parenthesis.
This generates a 3D plot. | |
| Rotate the graph | Hold down left mouse key and turn around and rotate the plot to your desire. |
| Zoom into graph | Zoom in slightly into graph to see a wavy surface.
Notice the surface is plotted in a wide mesh style. |
| Let's change some of the surface and graph properties.
Next, we will color both sides of the surface differently. | |
| >set hidden3d
>replot |
The required command for this is set space hidden3d
Let's type it. Replot to see the changed colors. |
| Now notice the hidden surface is colored green and the top surface is purple. | |
| >set isosamples 50,50 | Enter command, set space isosamples space 50 comma 50 |
| >replot | Replot to notice a finer mesh defining the surface. |
| Rotate the surface | To rotate, hold down left mouse key and move to your desired viewing angle |
| Close graph | Notice, the angle change in the top of the graphic window.
Next, close the graphic window. We will write a script to draw a sphere in gnuplot using a text editor. |
| Slide number 6
Polar coordinates and 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 Such functions can be plotted in polar co-ordinates. |
| We will practice to write scripts in a text file.
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 | Click on Search your computer and online resources icon |
| In search form type terminal and press enter | In search form type gedit and press enter to open gedit |
| I will use gedit text editor, windows users may use notepad software. | |
| Let's enter a comment on first line.
Comment starts with a hash. | |
| # my first 3D plot and press enter | I will type # my first 3D plot and press enter to start to start newline |
| Next, please type the commands as seen | |
| > set parametric | First set to parametric mode |
| >set angle degree | Then set angle to degree |
| >set urange [0:360]
>set vrange [0:360] |
Set u and v range |
| >set isosample 50,50 | Set isosamples to make a fine mesh |
| >set ticslevel 0 | Set tic level to zero. |
| >r=1 | I will set the radius to one. |
| Highlight
>splot r*cos(u)*cos(v),r*sin(u)*cos(v),r*sin(v) |
Next splot the function for sphere
Pause the video if necessary, and explore more. |
| Ctrl s | Press crtl s to save |
| Give file name – sphere.dem in desktop folder
click on save |
A dialogue box opens.
I will save the file in Desktop folder with name sphere.dem Click on Save |
| Close gedit, go to terminal | Minimize gedit.
Go back to the terminal where gnuplot was open If you had closed gnuplot, please open gnuplot again |
| >cd “~/Desktop” | On gnuplot prompt change directory to desktop
Use commands as seen on the screen Let's run the script to generate a sphere. |
| >load 'sphere.dem' | Type load space within single quotes sphere.dem |
| A plot of a sphere centered at zero, zero, zero with radius one appear on the screen
Next, say I want to change the sphere to blue color | |
| Go back to gedit script | Go back to the gedit window to edit the script.
If you had closed it, please open the script file to edit. |
| Add lc rgb 'red' in the end of splot command | Add lc space rgb space within single quotes blue |
| Save file | Save the changes in the script file |
| Go to gnuplot window | Come back to gnuplot and load the script file again as before |
>load 'sphere.dem'
Next, let's try a heatmap with pm3d command | |
| Highlight and delete,
lc rgb blue |
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 | Instead type in with space pm3d to generate surface with heatmap |
| Save script, minimize edit, go to gnuplot | Save the script file, minimize gedit and go to gnuplot |
| Highlight,
>load 'sphere.dem' |
Load the sphere.dem script again |
| Hover mouse on heat map guide | Notice the heatmap in the sphere
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. |
| Via scripts, we can generate and make changes to graphs easily.
Similar scripts are available in gnuplot demo website. | |
| Pause the video if required.
Practice and familiarize with commands and styles. | |
| Slide Number 7
Summary |
To summarize, in this tutorial, we learned to
|
| Slide Number 8
Summary |
* Plotted a sphere and formatted color
|
| Slide Number 9
Assignment |
For assignment, plot the following,
Plot 5 spheres in the graph with radius 0.5, 1, 2, 3 and 4 Center them differently Hint: To plot more than one function, separate them using comma sign |
| Slide Number 10
Assignment |
If you like to program, you may use a for loop
If sphere is centered at x1, y1,z1 equation takes the form as seen on the slide |
| 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.
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. |
| Thank you for joining. |