Difference between revisions of "Gnuplot/C2/Generate-3D-plots-and-surfaces/English"
PoojaMoolya (Talk | contribs) |
|||
(11 intermediate revisions by 3 users not shown) | |||
Line 8: | Line 8: | ||
|| '''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'''. | ||
Line 27: | Line 28: | ||
* Write, edit and execute a script | * Write, edit and execute a script | ||
* Draw a sphere | * Draw a sphere | ||
− | * Change the surface color of the sphere | + | * Change the surface color of the sphere and |
* Generate a heat map | * Generate a heat map | ||
|- | |- | ||
|| '''Slide Number 4''' | || '''Slide Number 4''' | ||
− | '''System | + | '''System Requirement''' |
|| | || | ||
* '''Ubuntu Linux''' 16.04 OS | * '''Ubuntu Linux''' 16.04 OS | ||
Line 63: | Line 64: | ||
|| Press '''Ctrl+L'''. | || Press '''Ctrl+L'''. | ||
|| I will also clear the screen. | || I will also clear the screen. | ||
+ | |||
We will plot the function, '''cos x cos y''' to draw a surface. | We will plot the function, '''cos x cos y''' to draw a surface. | ||
+ | |||
|- | |- | ||
|| Type '''splot cos(x)*cos(y)''' and press '''Enter'''. | || Type '''splot cos(x)*cos(y)''' and press '''Enter'''. | ||
|| Enter the 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. | Make sure '''x''' and '''y''' are in parenthesis. | ||
+ | |||
|- | |- | ||
|| Cursor on the graphics window. | || Cursor on the graphics window. | ||
− | || The splot command generates | + | || 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. | Besides '''x''' and '''y''', the third axis is the value of the function in the plot. | ||
Line 79: | Line 84: | ||
|| Hold down left mouse key and turn around and rotate the plot. | || Hold down left mouse key and turn around and rotate the plot. | ||
|| Hold down the left mouse key. | || Hold down the left mouse key. | ||
+ | |||
Move the mouse to rotate the graph and change the viewing angle. | Move the mouse to rotate the graph and change the viewing angle. | ||
Line 84: | Line 90: | ||
|| Zoom into the graph. | || Zoom into the graph. | ||
|| Zoom in slightly into the 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. | ||
Line 96: | Line 103: | ||
|- | |- | ||
|| Enter the command '''set hidden3d '''. | || Enter the command '''set hidden3d '''. | ||
+ | |||
Enter the command '''replot'''. | Enter the command '''replot'''. | ||
|| The required command for this is '''set space hidden3d''' . | || The required command for this is '''set space hidden3d''' . | ||
+ | |||
Enter the command '''replot''', to see the changed colors. | Enter the command '''replot''', to see the changed colors. | ||
Line 107: | Line 116: | ||
|| Type '''set isosamples 50,50 '''and press '''Enter'''. | || Type '''set isosamples 50,50 '''and press '''Enter'''. | ||
|| Let’s divide the surface into a fine grid. | || Let’s divide the surface into a fine grid. | ||
+ | |||
Enter the command, '''set space isosamples space 50 comma 50'''. | Enter the command, '''set space isosamples space 50 comma 50'''. | ||
|- | |- | ||
|| Type '''replot''' and press '''Enter'''. | || Type '''replot''' and press '''Enter'''. | ||
− | || '''Replot''' to notice a | + | || '''Replot''' to notice a fine mesh defining the surface. |
|- | |- | ||
Line 123: | Line 133: | ||
|- | |- | ||
|| Cursor on the view angle value, in the graphics window. | || Cursor on the view angle value, in the graphics window. | ||
+ | |||
Highlight the changed angle in the graphics window during video editing. | Highlight the changed angle in the graphics window during video editing. | ||
|| The viewing angle changes in the graphic window while rotating the graph. | || The viewing angle changes in the graphic window while rotating the graph. | ||
|- | |- | ||
− | || Close the graphic window. | + | || Click on Close button to close the graphic window. |
|| Next, we will plot a sphere in '''gnuplot'''. | || Next, we will plot a sphere in '''gnuplot'''. | ||
+ | |||
Close the graphics window. | Close the graphics window. | ||
|- | |- | ||
|| '''Slide number 6''' | || '''Slide number 6''' | ||
− | '''Equation for a | + | '''Equation for a Sphere''' |
+ | |||
This function can be plotted in parametric mode as, | This function can be plotted in parametric mode as, | ||
r.sin(u).cos(v), r.sin(u).sin(v),r.cos(u) | 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. | || 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. | 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. | This function can be plotted in parametric mode as seen here. | ||
Line 144: | Line 159: | ||
|| Cursor on the slide. | || Cursor on the slide. | ||
|| We will write a script to draw a sphere in '''gnuplot''' using the text editor. | || 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. | ||
Line 158: | Line 174: | ||
|| Type '''# my first 3D plot''' and press '''Enter'''. | || Type '''# my first 3D plot''' and press '''Enter'''. | ||
|| Let's enter a comment on the first line. | || Let's enter a comment on the first line. | ||
+ | |||
I will type '''hash my first 3D plot''' and press '''Enter''' to start a newline. | I will type '''hash my first 3D plot''' and press '''Enter''' to start a newline. | ||
+ | |||
The comments start with a '''hash'''. | The comments start with a '''hash'''. | ||
|- | |- | ||
− | || | + | ||Type the commands in the text editor. |
|| Next, please type the commands as shown here. | || Next, please type the commands as shown here. | ||
Line 191: | Line 209: | ||
|| Type '''set ticslevel 0''' and press '''Enter'''. | || Type '''set ticslevel 0''' and press '''Enter'''. | ||
|| Set '''ticks''' level to zero. | || Set '''ticks''' level to zero. | ||
+ | |||
This sets the '''XY''' plane at zero value of '''Z''' axis. | This sets the '''XY''' plane at zero value of '''Z''' axis. | ||
Line 203: | Line 222: | ||
|- | |- | ||
− | || Press '''Ctrl+S'''. | + | || Press '''Ctrl+ S'''. |
|| Press '''Control S''' to save the file. | || Press '''Control S''' to save the file. | ||
Line 209: | Line 228: | ||
|| Give file name, '''sphere.dem''' in path '''desktop''' folder. | || Give file name, '''sphere.dem''' in path '''desktop''' folder. | ||
Click on '''Save'''. | Click on '''Save'''. | ||
− | || A | + | || A dialog box opens. |
+ | |||
I will save the file in '''Desktop''' folder with filename '''sphere.dem'''. | I will save the file in '''Desktop''' folder with filename '''sphere.dem'''. | ||
+ | |||
Click on '''Save''' to save the script. | Click on '''Save''' to save the script. | ||
Line 216: | Line 237: | ||
|| Minimize '''gedit''' and go to '''terminal'''. | || Minimize '''gedit''' and go to '''terminal'''. | ||
|| Click on the hyphen sign on the top to minimize the gedit window. | || Click on the hyphen sign on the top to minimize the gedit window. | ||
+ | |||
Go back to the '''terminal''', where '''gnuplot''' is open. | Go back to the '''terminal''', where '''gnuplot''' is open. | ||
Line 221: | Line 243: | ||
|| Cursor on '''terminal'''. | || Cursor on '''terminal'''. | ||
|| If you had closed '''gnuplot''', please open '''gnuplot''' again. | || If you had closed '''gnuplot''', please open '''gnuplot''' again. | ||
+ | |||
Let's run the script to generate a sphere. | Let's run the script to generate a sphere. | ||
Line 234: | Line 257: | ||
|| Rotate the sphere. | || Rotate the sphere. | ||
|| Let’s change the color of the sphere to blue. | || Let’s change the color of the sphere to blue. | ||
+ | |||
We will edit the script file to make the required changes. | We will edit the script file to make the required changes. | ||
Line 239: | Line 263: | ||
|| Go to the '''gedit''' script . | || Go to the '''gedit''' script . | ||
|| Go to the edit window to edit the script. | || Go to the edit window to edit the script. | ||
+ | |||
If you had closed it, please open the '''script''' file to edit. | 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 rgb 'blue'''' in the end of the splot command. | ||
− | || Add '''lc space rgb space''' within single quotes '''blue''' . | + | || Add '''lc space rgb space''' within single quotes '''blue'''. |
− | + | ||
|- | |- | ||
Line 257: | Line 282: | ||
|| Type '''load 'sphere.dem'''' and press '''Enter'''. | || Type '''load 'sphere.dem'''' and press '''Enter'''. | ||
|| Enter the command '''load''' space within single quotes '''sphere.dem'''. | || Enter the command '''load''' space within single quotes '''sphere.dem'''. | ||
+ | |||
In some systems, pressing the up arrow key scrolls through the command history. | In some systems, pressing the up arrow key scrolls through the command history. | ||
|- | |- | ||
|| Show the blue sphere. | || Show the blue sphere. | ||
− | Notice the blue sphere in the graphics window. | + | || Notice the blue sphere in the graphics window. |
|- | |- | ||
Line 271: | Line 297: | ||
'''lc rgb blue''' . | '''lc rgb blue''' . | ||
|| Go back to the script in '''gedit''' to make changes in it. | || Go back to the script in '''gedit''' to make changes in it. | ||
+ | |||
Delete the '''lc space rgb space blue''' in the splot command. | Delete the '''lc space rgb space blue''' in the splot command. | ||
Line 288: | Line 315: | ||
|| Point mouse next to the map guide in graphics window. | || Point mouse next to the map guide in graphics window. | ||
|| Notice the '''heatmap''' in the sphere. | || Notice the '''heatmap''' in the sphere. | ||
+ | |||
The color scale bar for the color gradient, is visible on the side. | The color scale bar for the color gradient, is visible on the side. | ||
Line 293: | Line 321: | ||
|| Hover mouse on the range guide range. | || Hover mouse on the range guide range. | ||
|| This is called a '''colorbox''' in '''gnuplot'''. | || This is called a '''colorbox''' in '''gnuplot'''. | ||
− | The values between 1 | + | |
+ | The values between 1 and 0.8 are colored in yellow. | ||
+ | |||
Values between minus 0.8 to minus 1 are colored in deep purple. | Values between minus 0.8 to minus 1 are colored in deep purple. | ||
Line 303: | Line 333: | ||
|| Exit '''gnuplot''' and '''gedit'''. | || Exit '''gnuplot''' and '''gedit'''. | ||
|| Let’s 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'''. | || Cursor on the '''terminal'''. | ||
− | || | + | || Practise and familiarize with commands and styles. |
+ | |||
Learners can also use the help command for this purpose. | Learners can also use the help command for this purpose. | ||
Line 336: | Line 368: | ||
'''Assignment''' | '''Assignment''' | ||
|| For assignment, plot the following, | || For assignment, plot the following, | ||
− | * Plot | + | * Plot five spheres in a graph with different radius. |
* Center and color the spheres differently. | * Center and color the spheres differently. | ||
Line 342: | Line 374: | ||
|| '''Slide Number 10''' | || '''Slide Number 10''' | ||
'''Assignment''' | '''Assignment''' | ||
+ | |||
Hint: | Hint: | ||
For a sphere centered at (x1,y1,z1), use the equation for sphere as seen here. | For a sphere centered at (x1,y1,z1), use the equation for sphere as seen here. | ||
Line 356: | Line 389: | ||
'''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. | ||
Line 362: | Line 396: | ||
'''Spoken Tutorial workshops''' | '''Spoken Tutorial workshops''' | ||
|| We conduct workshops and give certificates. | || We conduct workshops and give certificates. | ||
+ | |||
For more details, please write to us. | For more details, please write to us. | ||
|- | |- | ||
|| '''Slide Number 13''' | || '''Slide Number 13''' | ||
− | '''Forum for | + | '''Forum for Specific Questions:''' |
|| Post your timed queries in the '''forum'''. | || Post your timed queries in the '''forum'''. | ||
|- | |- | ||
|| '''Slide Number 14''' | || '''Slide Number 14''' | ||
− | ''' | + | '''Acknowledgements''' |
|| '''Spoken Tutorial Project''' is funded by '''MHRD''', '''Government of India'''. | || '''Spoken Tutorial Project''' is funded by '''MHRD''', '''Government of India'''. | ||
Line 377: | Line 412: | ||
|| | || | ||
|| This is Rani from IIT Bombay. | || This is Rani from IIT Bombay. | ||
+ | |||
Thank you for joining. | 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,
|
Slide Number 3
Learning Objectives |
|
Slide Number 4
System Requirement |
|
Slide Number 5
Pre-requisites |
To follow this tutorial,
|
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
|
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,
|
Slide Number 8
Summary |
|
Slide Number 9
Assignment |
For assignment, plot the following,
|
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. |