Difference between revisions of "Gnuplot/C2/Multiple-plots-in-a-canvas/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with " {| border=1 |- || Visual Cue || Narration |- || '''Slide Number 1''' '''Title Slide ''' '''Multiple plots in a canvas''' || Welcome to the tutorial on '''Multiple plots in a...")
 
Line 1: Line 1:
 
+
{| border = 1
{| border=1
+
|| '''Visual Cue'''
|-
+
|| '''Narration'''
|| Visual Cue
+
|| Narration
+
  
 
|-
 
|-
Line 9: Line 7:
 
'''Title Slide '''
 
'''Title Slide '''
 
'''Multiple plots in a canvas'''
 
'''Multiple plots in a canvas'''
|| Welcome to the tutorial on '''Multiple plots in a canvas'''
+
|| Welcome to the tutorial on '''Multiple plots in a canvas'''.
  
 
|-
 
|-
 
|| '''Slide Number 2'''
 
|| '''Slide Number 2'''
 
'''Learning Objectives'''
 
'''Learning Objectives'''
|| In this tutorial, we will learn to,
+
|| In this tutorial we will learn to,
 
* Generate multiple plots in one canvas
 
* Generate multiple plots in one canvas
* Make multiplot graph via script
+
* Make a multiplot graph using script commands
 
* Define placement and size of graphs in canvas
 
* Define placement and size of graphs in canvas
* Generate interactive output and file for printing or sharing
 
  
 
|-
 
|-
 
|| '''Slide Number 3'''
 
|| '''Slide Number 3'''
 +
'''Learning Objectives'''
 +
|| * Add a rectangle object in the background
 +
* Generate output on the screen and
 +
* Save the output to '''svg''' file
 +
 +
|-
 +
|| '''Slide Number 4'''
 
'''Pre-requisites'''
 
'''Pre-requisites'''
 
|| To record this tutorial, I am using,  
 
|| To record this tutorial, I am using,  
* Debian linux 9.3
+
 
* Gedit text  editor 3.22
+
* '''Ubuntu Linux''' 16.04 OS
* And gnuplot 5.2.5
+
* '''Gedit''' version 3.18 and
 +
* '''gnuplot''' version 5.2.6
  
 
|-
 
|-
|| '''Slide Number 4'''
+
|| '''Slide Number 5'''
 
'''System and Software Requirement'''
 
'''System and Software Requirement'''
|| To follow this tutorial, learners must be familiar with,
+
[https://spoken-tutorial.org/ https:spoken-tutorial.org]
Basic computer and internet skills
+
|| To follow this tutorial,  
Concept of graphing and
+
* Learner must be familiar with basic of gnuplot.
College level Mathematics skills
+
* For pre-requisite tutorials, please visit this site.
  
 
|-
 
|-
 +
|| '''Slide Number 5'''
 +
'''Code files'''
 
||  
 
||  
|| '''Multiplot''' command allow us to plot multiple graphs in a single plotting canvas.  
+
* The files used in this tutorial are provided in the '''Code files''' link.
I will demonstrate with four separate graphs in one canvas
+
* Please download and extract them.
  
 
|-
 
|-
|| Press ctrl alt t
+
|| Press '''Ctrl+Alt+T'''.
cd Desktop
+
Enter the command '''cd Desktop'''.
|| Press '''control alt t''' keys together to open a terminal.
+
|| Open a '''terminal''' and change the directory to '''Desktop'''.
Change to Desktop directory.
+
I will demonstrate the '''multiplot''' command, with four graphs in one canvas.
  
 
|-
 
|-
|| '''Gedit'''
+
|| Type '''gedit &''' and press '''Enter'''.
press enter
+
|| Type '''gedit space ampersand''' and press '''Enter''' to open '''gedit'''.
|| Type '''gedit''' and press enter, to open gedit.
+
The '''ampersand''' makes the process run in the background.
We will write the commands in a text file and run the script file to plot graph.
+
It detaches the process from the '''terminal'''.
  
 
|-
 
|-
||  
+
|| Cursor on gedit window.
|| I will use gedit text editor, windows users may use notepad software.
+
|| '''Windows''' users may use '''notepad''' or '''wordpad'''.
We can edit the '''script''' file to make any required changes in the graph.
+
We will write the required commands in a text file.
  
 
|-
 
|-
|| '''# my first multiplot''' and press enter
+
|| Type, '''# my first multiplot''' and press '''Enter'''.
|| I will type '''hash my first multiplot''' and press enter
+
|| I will type '''hash my first multiplot''' and press '''Enter''' .
This is a comment line
+
This is a comment line.
  
 
|-
 
|-
||  
+
|| Type '''set multiplot''', press '''Enter'''.
|| Next, type the commands as seen in the video.  
+
|| Next, set the '''environment''' to '''multiplot''' mode, as '''set space multiplot'''.
I will explain them to you.
+
Start a new line and leave a blank line for clarity.
  
 
|-
 
|-
|| '''set multiplot''', press enter
+
|| Cursor on '''gedit''' window.
|| First, set the environment to multiplot as '''set space multiplot'''
+
|| We will plot, '''sin x, cos x''', a '''straight line''' and an '''exponential decay''' graph.
Start a new line
+
  
 
|-
 
|-
||  
+
|| Type header line,
|| We will plot, '''sin x, cos x''', a '''straight line''' and an '''exponential decay''' curve.
+
I will start with the script for '''sin x'''
+
 
+
 
+
|-
+
|| Highlight and type
+
 
'''#x-sin(x) plot'''
 
'''#x-sin(x) plot'''
|| Enter the commands, as seen in the video to specify placement and size
+
|| I will start with the script for the '''sin(x)''' part.
 +
In the next line, enter a comment to identify that, the plot is for '''sin x'''.
  
 
|-
 
|-
|| Highlight and type
+
|| Type lines,
 
'''set origin 0,0'''
 
'''set origin 0,0'''
 
 
'''set size 0.5, 0.5'''
 
'''set size 0.5, 0.5'''
|| The plot is set in position 0 , 0 in origin
+
|| Enter the next two commands define the size and placement for the '''sin x''' plot.
Here I am specifying plot size to be a square of point 5 by point 5
+
  
 
|-
 
|-
|| Highlight and type,
+
|| Hover mouse next to '''set origin 0,0''' .
'''set xrange[-10:10]
+
|| This plot is set at position zero, zero which is the origin.
 +
This is the left hand bottom corner of the page.
  
set yrange[-2:2]'''
+
|-
 +
|| Hover mouse next to '''set size 0.5,0.5''' .
 +
|| Here I am specifying plot size to be a square of point 5 by point 5.
 +
This size is relative to the total page size and makes it a quarter of the page.
  
 +
|-
 +
|| Type the following lines,
 +
'''set xrange[-10:10] yrange[-2:2]'''
 
'''set title '”x-sin(x) plot”'''
 
'''set title '”x-sin(x) plot”'''
 
 
'''plot sin(x) '''
 
'''plot sin(x) '''
|| Next, we will set x and y range, and title
+
|| Next, we will set x and y range, and title for the '''sin (x)''' part of the plot.
Then, issue the plot command.
+
These are the graph formatting details for the plot '''sin x'''.
  
 
|-
 
|-
 
|| Type,
 
|| Type,
'''# x-cos (x) plot'''
+
'''# cos (x) - x plot'''
|| Now, I will enter details for the second plot, x, cos x.
+
|| Now, I will enter details for the second plot, which is '''cos x'''.
First, write a comment to indicate it is the part of the script for cos x.  
+
First, write a comment line, to indicate it is the part for cos (x), in the script.
Type hash x cos x plot.
+
Type '''hash cos x - x''' plot.
Press enter.
+
  
 
|-
 
|-
|| '''set origin 0.5,0.0 '''
+
|| Type the lines,
 
+
'''set origin 0.5,0.0 '''
 
'''set size 0.5, 0.5 '''
 
'''set size 0.5, 0.5 '''
 
 
'''set xrange[-10:10] '''
 
'''set xrange[-10:10] '''
 +
'''set yrange[-2:2] '''
 +
'''set title "x-cos(x) graph" '''
 +
'''plot cos(x) notitle '''
 +
|| Enter the commands as seen and pause the video as and when necessary.
  
'''set yrange[-2:2]
+
|-
 +
|| Hover mouse next to '''set origin''' and '''set size'''.
 +
|| Here, I specify the position and size of the second plot.
 +
The position is set to the right side of the '''sin x''' plot.
  
set title "x-cos(x) graph" '''
+
|-
 
+
|| Show the '''data.txt''' file icon in '''Desktop'''.
'''plot cos(x) notitle '''
+
|| I will use the data from the text file '''data.txt''', for the third and fourth plots.
|| Enter commands as seen in the video.
+
This file is provided to you in the '''Code files''' link of this tutorial.
When necessary, pause the video.
+
I have downloaded and saved the file on '''Desktop'''.
Here, I specify the position and size of the second plot.
+
Set position of the plot to the right of x sin x plot.
+
  
 
|-
 
|-
||  
+
|| Show screenshot of the file.
|| For third and fourth plots, I will use the data from a text file.
+
|| The file has 3 data columns, '''x''' , '''y1''' and '''y2''' .
It is named ‘’’data dot txt’’’ and saved in the desktop directory for me.
+
The file is also provided to you with the tutorial.
+
  
 
|-
 
|-
Line 139: Line 145:
 
'''#straight line plot'''
 
'''#straight line plot'''
 
|| Now, I will enter details for the third plot.
 
|| Now, I will enter details for the third plot.
Make a comment, starting with a hash.
+
Write a comment, starting with a hash
Type, '''straight line plot''' and press enter
+
Type, '''straight line plot''' and press '''Enter'''.
Again specify the size and position.
+
Position places the graph on top right corner.
+
  
 
|-
 
|-
|| '''set origin 0.5,0.5 '''
+
|| Type the lines,
 +
 
 +
'''set origin 0.5,0.5 '''
  
 
'''set size 0.5, 0.5 '''
 
'''set size 0.5, 0.5 '''
 +
|| Again specify the size and position for this graph.
  
'''set title "straight line" '''
 
  
 +
The position places the graph in top right corner.
 +
|-
 +
|| Type the lines,
 +
'''set title "straight line" '''
 
'''set xrange[*:*] '''
 
'''set xrange[*:*] '''
 
 
'''set yrange[*:*] '''
 
'''set yrange[*:*] '''
 
 
'''plot 'data.txt' using 1:3 with linespoint notitle '''
 
'''plot 'data.txt' using 1:3 with linespoint notitle '''
|| Enter commands as seen in video.
+
and press '''Enter'''.
Please pause the video when required.
+
|| Enter the commands as seen in on the screen.
Enter the formatting properties for the plot.
+
Specify the title and autoscale axis range and issue the plot command.
  
 
|-
 
|-
|| Hover mouse over '''origin''', '''xrange''' and '''yrange'''
+
|| Hover mouse over '''1:3''' in the '''plot''' command.
|| The stars specifies auto scale for axis range.
+
|| The 3rd column in the data file is the y data values for the straight line plot.
Issue the plot command in the end.
+
Here, I want column one as x data and column three as y data.
+
In the plot command, I also specify, no legend title is required.
+
  
 
|-
 
|-
||  
+
|| Cursor in '''gedit''' window.
|| Next, let's write script to generate the exponential decay plot.
+
|| Pause the video when required to enter the commands.
  
 
|-
 
|-
|| Type, '''#Exponential decay'''
+
|| Hover mouse over '''origin''', '''xrange''' and '''yrange'''.
|| I will type hash exponential decay for the comment.
+
|| The stars specify autoscale for axes range.
  
 
|-
 
|-
|| '''set origin 0.0,0.5 '''
+
|| Hover mouse next to '''1:3''' .
|| Set position to top left, above the sin x plot
+
Hover mouse next to '''notitle'''.
Set size and title for the graph.
+
|| Here I am using column 1 for '''x''' data and column 3 for '''y''' data.
 +
Here I also specify, no legend title is required in the plot.
  
 
|-
 
|-
|| '''set size 0.5, 0.5 '''
+
|| Cursor in '''gedit''' window.
 +
|| Next, let's write the part of '''script''' to generate the exponential decay plot.
  
'''set title "Exponential decay" '''
+
|-
 +
|| Type, '''#Exponential decay''' and
 +
press '''Enter'''.
 +
|| I will type '''hash exponential decay''' for the comment line.
  
'''set autoscale '''
+
|-
 +
|| Type,
 +
'''set origin 0.0,0.5 '''
 +
and press '''Enter'''.
 +
|| For this plot, set the position above the '''sin x''' in the top left corner.
  
 +
|-
 +
|| Type,
 +
'''set size 0.5, 0.5 '''
 +
'''set title "Exponential decay" '''
 +
'''set autoscale '''
 
'''plot 'data.txt' using 1:2 with linespoint notitle '''
 
'''plot 'data.txt' using 1:2 with linespoint notitle '''
|| I will also autoscale the data for axis range.
+
and press '''Enter'''.
I will read the x and y data from the data file in the plot command
+
|| Set size, title for graph and autoscale data.
Here, column one and column two are used for x y data.
+
Read in the columns for '''x''' and '''y''' data from the data file in the '''plot''' command.
  
 
|-
 
|-
|| >'''unset multiplot'''
+
|| Press '''Enter'''.
|| Finally, unset the multiplot mode with command, '''unset space multiplot'''
+
Type '''unset multiplot''' and press '''Enter'''.
 +
|| I will leave an blank line after this.
 +
Finally, '''unset''' the '''multiplot''' mode with the command, '''unset space multiplot'''.
  
 
|-
 
|-
|| '''Press ctrl-S'''
+
|| Press '''ctrl+S'''.
|| Press '''ctrl-S''' to open the file save dialogue box.
+
|| Press '''ctrl S''' to open the file '''save as''' dialogue box.
  
 
|-
 
|-
|| Type filename, '''multiplot.dem'''  
+
|| Type filename as, '''multiplot.dem'''  
click on '''save'''
+
Click on '''save'''.
|| I will give file name '''multiplot dot dem''' and choose '''Desktop''' directory for path.
+
|| Save the file in '''Desktop''' directory with filename '''multiplot.dem'''.
Click on '''save''' to save the script
+
Click on '''save''' to save the script.
  
 
|-
 
|-
|| Minimize '''gedit'''
+
|| Minimize '''gedit'''.
open terminal
+
|| Click on '''save''' and Minimize the '''gedit''' window.  
|| Click to minimize '''gedit'''.
+
Let's open another terminal.
+
  
 
|-
 
|-
|| Ctrl alt t
+
|| Go to terminal and press '''Enter'''.
|| Press '''control atl t''' keys together to open a terminal
+
|| Go to the '''terminal''' and press '''Enter''' to get the '''terminal''' prompt.
  
 +
|-
 +
|| Type '''gnuplot''' and press '''Enter'''.
 +
|| Let’s open '''gnuplot''' .
  
 
|-
 
|-
|| '''cd Desktop”'''
+
|| Press '''Ctrl+L''' .
|| Change directory to '''desktop'''
+
|| I will also clear the screen.
  
 
|-
 
|-
||Type, '''gnuplot'''
+
|| Cursor in the '''terminal'''.
Press enter
+
|| Let's run the script to generate the '''multiplot'''.
||Open gnuplot from this terminal
+
  
 
|-
 
|-
|| Press '''control shift k'''.
+
|| Type '''load 'multiplot.dem'''' and press '''Enter'''.
|| I will clear the screen and bring prompt to top of the screen for clarity in video.
+
|| Enter the command, '''load''' space in single quotes, '''multiplot.dem'''.
Let's run the script to generate the '''multiplot'''.
+
  
 
|-
 
|-
|| '''load 'multiplot.dem''''
+
|| Show the graphics window with 4 plots.
Press '''enter'''
+
|| A graphic window with four graphs opens in the canvas.
|| Type '''load''' space in single quotes, '''multiplot dot dem'''
+
Press '''enter'''
+
  
 
|-
 
|-
||  
+
|| Show '''multiplot mode terminal prompt''' video patch from another '''terminal'''.
|| A graphics window with four graphs in the canvas opens.
+
For this type, '''multiplot''' in '''gnuplot''' prompt.
I notice a few formatting modifications could improve the view.
+
|| In case of errors in the script, '''gnuplot''' will remain in the '''multiplot''' mode.
 +
 
 +
|-
 +
|| Type '''unset space multiplot''' and press '''Enter'''.
 +
|| Then the graphics plot is also not generated.
 +
If so, type '''unset space multiplot'''.
 +
 
 +
|-
 +
|| Cursor on the '''terminal'''.
 +
|| To '''reset''' the default setting, the '''unset''' command is used.
 +
If we do not '''unset''' the format, the set format will not '''reset''' to default setting.
 +
 
 +
 
 +
|-
 +
|| Hover mouse next to '''gnuplot''' prompt.
 +
|| This returns the terminal to '''gnuplot''' prompt.
 +
If Debug the '''script''' to make it error free and run the script to generate the plot.
 +
 
 +
|-
 +
|| Go to the graphics window.
 +
|| A few formatting modifications could improve the look of the graphs.
  
 
|-
 
|-
 
|| Close the graphics window.
 
|| Close the graphics window.
|| Hence, make the modifications in the script next.
+
|| Hence, I will make the following modifications in the script. next.
 
Close the graphics window.
 
Close the graphics window.
  
 
|-
 
|-
|| Go back to '''gedit''' script
+
|| Go back to '''gedit''' script.
|| Go back to gedit to edit the script.
+
|| Go back to the '''gedit''' window to edit the script.
 
If you had closed it, please open the script file to edit it further.
 
If you had closed it, please open the script file to edit it further.
  
 
|-
 
|-
||  
+
|| Scroll to the '''sin(x)''' script part.
|| Let's change the background color of the sin x plot.
+
Start a new line before plot command.
 +
|| Scroll to the '''sin x''' part of the script.
 +
Let's change the background color of the '''sin x''' plot.
 +
Start a new line before the '''plot''' command.
  
 
|-
 
|-
|| '''set object 1 rectangle from graph 0,0 to graph 1,1 behind fillcolor rgb 'cyan' fillstyle solid noborder'''
+
|| Type
|| Scroll to the sin x script and start a new line before the plot command.
+
'''set object 1 rectangle from graph 0,0 to graph 1,1 behind fillcolor rgb 'cyan' fillstyle solid noborder'''
To change background color, we will insert an object, in the graph.
+
and press '''Enter'''.
Enter the command as seen in the video.
+
|| To change background color, we will insert an object, in the graph.
 +
Enter the command as seen on the screen.
  
 
|-
 
|-
|| Hover mouse next to '''cyan''' and '''noborder'''
+
|| Hover mouse next to '''object,''' '''cyan''' and '''noborder'''.
|| Here, we set a rectangle object, with cyan color for background, without border.
+
|| Here, we set a cyan colored rectangle, without border, for background.
  
 
|-
 
|-
||unset object
+
|| Start a new line after the '''plot''' command.
||After the plot command unset the object
+
Type,''' unset object 1''' and press '''Enter'''.
Type, unset space object
+
|| Start a new line after the '''plot''' command.
 +
'''Unset''' the cyan background object, as shown here.
  
 
|-
 
|-
|| '''set format y "10^{%L}" '''
+
|| Type in the three lines above the '''plot''' command line,
 +
'''set format y "10^{%L}" '''
 
'''set xtics rotate '''
 
'''set xtics rotate '''
 
+
'''set ytics 40000'''  
'''set ytics 40000'''
+
and press '''Enter'''.
|| Next, add modifications on the script on axis formats, for straight line plot.
+
|| Next, For the straight line plot, add modifications on axis formats.
Enter the commands as seen in the video.
+
The commands are added before the '''plot''' command as shown.
  
 
|-
 
|-
|| Hover mouse over the change.
+
|| Point mouse to '''set format y''', then to '''xtics rotate''' and then '''ytics 40000'''.
||The y axis numbers are large.  
+
|| The '''y''' axis numbers are large.  
 
So I will change the notation.
 
So I will change the notation.
I will also rotate the x axis label y tics spacing.
+
I will also rotate the '''x''' axis tics in the plot label.
 +
I also specify the '''y''' tics spacing.
  
 
|-
 
|-
|| '''unset format y'''
+
|| Type '''unset format y '''.
|| Unset y axis format after the plot command is executed.
+
|| We will '''unset''' the '''y''' axis format after the '''plot''' command is executed.
  
 
|-
 
|-
||  
+
|| Scroll down the script file.
|| Next, go to the exponential decay part.
+
|| Next go to the part of '''exponential decay''' script .
  
 
|-
 
|-
|| '''set format y "10^{%L}" '''
+
|| Before the plot command, type in the three lines,
 +
'''set format y "10^{%L}" '''
 
'''set xtics rotate '''
 
'''set xtics rotate '''
 
 
'''set ytics 40000 '''
 
'''set ytics 40000 '''
|| Add the formatting commands, before the plot command as seen on the screen
+
and press '''Enter'''.
 +
|| I will add the same formatting commands, as in the straight line plot.
 +
Notice that, they are added before the '''plot''' command.
  
 
|-
 
|-
||  
+
|| Type, '''unset format y''' after the plot command.
|| This specifies y axis label format and rotates x axis label
+
|| Start a new line after plot command and '''unset''' the format of '''y-axis'''.
Set y tics spacing to forty thousand.
+
  
 
|-
 
|-
|| Type, '''unset format y'''
+
|| Scroll to top of the script.
|| Start a new line after plot command.
+
|| Let's add command to print the graph into an image file.
Enter command unset space format space y to unset '''y axis''' format.
+
Scroll up to the top of the script file.
  
 
|-
 
|-
|| Now let’s add command to print the graph to an image file.
+
|| Before the set multiplot line, type,
|| Scroll up to the top of the script.
+
'''set terminal svg size 800,800 enhanced font 'Verdana,12' '''
 +
|| Type set term to '''svg''' as seen before starting the multiplot mode.
  
 
|-
 
|-
|| '''set terminal svg size 800,800 enhanced font 'Verdana,12' '''
+
|| Type
'''set output 'multiplot.svg''''
+
'''set output 'multiplot.svg'''' and press '''Enter'''.
|| Set terminal to '''svg''' as seen in the video.
+
|| Direct the output to a '''svg''' file as seen.
Svg is scalable vector graphics.
+
These are done before the '''multiplot''' command is executed.
  
 
|-
 
|-
||  
+
|| Scroll to the bottom of the script.
|| Direct the output to a '''svg''' file
+
|| Scroll to the bottom of script file and '''unset''' the '''output'''.
This is done before the '''multiplot''' command is executed
+
This is done after before we '''unset''' the '''multiplot''' mode.
  
 
|-
 
|-
|| '''unset output'''
+
|| Type '''unset output '''and press '''Enter'''.
'''ctrl s'''
+
|| Enter the command '''unset''' '''space''' '''output'''.
|| Scroll to the bottom of script file and '''unset''' the '''output'''
+
Type '''unset''' '''space''' '''output'''
+
Press '''ctrl s''' to '''save''' the file.
+
  
 
|-
 
|-
|| Go to terminal
+
|| Press '''Ctrl+S '''and minimize '''gedit'''.
>'''load 'multiplot.dem''''
+
|| Press '''Ctrl-S''' to '''save''' the file and minimize '''gedit'''.
Press '''enter'''
+
|| Minimize gedit.
+
Go back to '''terminal''' where '''gnuplot''' was open.
+
Run the updated '''multiplot dot dem''' script.
+
  
 
|-
 
|-
||  
+
|| Go to the '''terminal'''.
|| If you had closed gnuplot, please open gnuplot again
+
|| Go back to the '''terminal''' from where '''gnuplot''' was opened.
This time, the output is directed to a file.
+
If you had closed '''gnuplot''', please open '''gnuplot''' again.
The graphics window does not open.
+
The output file is generated in the '''Desktop''' directory.
+
  
 
|-
 
|-
||  
+
|| Enter the command '''load 'multiplot.dem'''' .
|| In case of errors in the script, gnuplot may remain in '''multiplot''' mode.
+
|| Run the updated '''multiplot.dem''' script.
If so, type '''unset space multiplot'''
+
Now, the graphics window does not open, since the output is a '''svg''' file, .
This returns to gnuplot prompt
+
  
 
|-
 
|-
|| Go to '''Desktop'''
+
|| Enter the command '''quit'''.
|| Go to '''Desktop'''  
+
|| Enter the command '''quit''', to quit '''gnuplot'''.
  
 
|-
 
|-
|| Open '''multiplot.svg'''
+
|| Go to '''Desktop'''.
|| Double click on the '''multiplot dot svg''' file icon to view it.
+
|| Go to '''Desktop''' .
  
 
|-
 
|-
||  
+
|| Open '''multiplot.svg''' file.
|| You may add desired formatting to the script file.
+
|| Open the file, '''multiplot.svg''' that is created on the '''Desktop'''.
Notice the cyan background only in the the x sin x plot
+
Since the path is '''Desktop''' the output file is generated in the '''Desktop''' directory.
  
 
|-
 
|-
||  
+
|| Cursor on the '''svg''' file.
|| Similar scripts are available in '''gnuplot''' demo website.
+
|| You may add commands to the script file to generate the desired output.
I encourage you to practice and familiarize with commands and styles.
+
  
 
|-
 
|-
|| '''Slide Number 5'''
+
|| Close the image file.
 +
|| Similar scripts are available in the '''gnuplot''' demo website.
 +
Practice and familiarize with the commands and styles.
 +
I will close the image file.
 +
 
 +
|-
 +
|| '''Slide Number 6'''
 
'''Summary'''
 
'''Summary'''
|| Now, to summarize, in this tutorial, we  
+
|| Now, to summarize, in this tutorial, we * Learned the '''multiplot''' command
* Learned '''multiplot''' command
+
* Defined placement and size of plot in canvas
* Learned to define placement and size of graph in canvas
+
* Wrote, modified and executed script
+
 
* Generated four plots in a canvas
 
* Generated four plots in a canvas
* Generated interactive output and
+
* Added a rectangle object
* Generated an image output  
+
* Generated output on the screen and
 +
* Generated a '''svg''' image file output  
  
 
|-
 
|-
|| '''Slide Number 6'''
+
|| '''Slide Number 7'''
'''Assignment'''
+
'''Assignment 1'''
 
|| For assignment activity, please do the following.
 
|| For assignment activity, please do the following.
Plot 4 '''parabolas''' opening in 4 different quadrants, in a 2 by 2 '''multiplot'''
+
* Plot 4 '''parabolas''' opening to 4 different quadrants in a 2 x 2 '''multiplot'''.
 +
* Give a different background color for each plot.
  
 
|-
 
|-
|| '''Slide Number 7'''
+
|| '''Slide Number 8'''
 +
'''Assignment 2'''
 +
|| With the '''data.txt''', provided, do the following.* Generate one plot covering the canvas with x-y1 data points.
 +
* Draw an inset graph, with x-y2 data points.
 +
 
 +
|-
 +
|| Show assignment result screenshot.
 +
|| Completed assignment looks similar to this.
 +
 
 +
|-
 +
|| '''Slide Number 9'''
 
'''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 8'''
+
|| '''Slide Number 10'''
 
'''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 9'''
+
|| '''Slide Number 11'''
 
'''Forum for specific questions:'''
 
'''Forum for specific questions:'''
|| Post your timed queries in the forum.
+
|| Post your timed queries in the '''forum'''.
  
 
|-
 
|-
|| '''Slide Number 10'''
+
|| '''Slide Number 12'''
 
'''Acknowledgement'''
 
'''Acknowledgement'''
|| Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
+
|| '''Spoken Tutorial Project''' is funded by '''MHRD''', '''Government of India'''.
  
 
|-
 
|-
 
||  
 
||  
|| This is Rani from IIT Bombay.  
+
|| This is Rani from IIT, Bombay.  
 
Thank you for joining.
 
Thank you for joining.
 +
 
|-
 
|-
 
|}
 
|}

Revision as of 11:39, 3 January 2020

Visual Cue Narration
Slide Number 1

Title Slide Multiple plots in a canvas

Welcome to the tutorial on Multiple plots in a canvas.
Slide Number 2

Learning Objectives

In this tutorial we will learn to,
  • Generate multiple plots in one canvas
  • Make a multiplot graph using script commands
  • Define placement and size of graphs in canvas
Slide Number 3

Learning Objectives

* Add a rectangle object in the background
  • Generate output on the screen and
  • Save the output to svg file
Slide Number 4

Pre-requisites

To record this tutorial, I am using,
  • Ubuntu Linux 16.04 OS
  • Gedit version 3.18 and
  • gnuplot version 5.2.6
Slide Number 5

System and Software Requirement https:spoken-tutorial.org

To follow this tutorial,
  • Learner must be familiar with basic of gnuplot.
  • For pre-requisite tutorials, please visit this site.
Slide Number 5

Code files

  • The files used in this tutorial are provided in the Code files link.
  • Please download and extract them.
Press Ctrl+Alt+T.

Enter the command cd Desktop.

Open a terminal and change the directory to Desktop.

I will demonstrate the multiplot command, with four graphs in one canvas.

Type gedit & and press Enter. Type gedit space ampersand and press Enter to open gedit.

The ampersand makes the process run in the background. It detaches the process from the terminal.

Cursor on gedit window. Windows users may use notepad or wordpad.

We will write the required commands in a text file.

Type, # my first multiplot and press Enter. I will type hash my first multiplot and press Enter .

This is a comment line.

Type set multiplot, press Enter. Next, set the environment to multiplot mode, as set space multiplot.

Start a new line and leave a blank line for clarity.

Cursor on gedit window. We will plot, sin x, cos x, a straight line and an exponential decay graph.
Type header line,

#x-sin(x) plot

I will start with the script for the sin(x) part.

In the next line, enter a comment to identify that, the plot is for sin x.

Type lines,

set origin 0,0 set size 0.5, 0.5

Enter the next two commands define the size and placement for the sin x plot.
Hover mouse next to set origin 0,0 . This plot is set at position zero, zero which is the origin.

This is the left hand bottom corner of the page.

Hover mouse next to set size 0.5,0.5 . Here I am specifying plot size to be a square of point 5 by point 5.

This size is relative to the total page size and makes it a quarter of the page.

Type the following lines,

set xrange[-10:10] yrange[-2:2] set title '”x-sin(x) plot” plot sin(x)

Next, we will set x and y range, and title for the sin (x) part of the plot.

These are the graph formatting details for the plot sin x.

Type,

# cos (x) - x plot

Now, I will enter details for the second plot, which is cos x.

First, write a comment line, to indicate it is the part for cos (x), in the script. Type hash cos x - x plot.

Type the lines,

set origin 0.5,0.0 set size 0.5, 0.5 set xrange[-10:10] set yrange[-2:2] set title "x-cos(x) graph" plot cos(x) notitle

Enter the commands as seen and pause the video as and when necessary.
Hover mouse next to set origin and set size. Here, I specify the position and size of the second plot.

The position is set to the right side of the sin x plot.

Show the data.txt file icon in Desktop. I will use the data from the text file data.txt, for the third and fourth plots.

This file is provided to you in the Code files link of this tutorial. I have downloaded and saved the file on Desktop.

Show screenshot of the file. The file has 3 data columns, x , y1 and y2 .
Type

#straight line plot

Now, I will enter details for the third plot.

Write a comment, starting with a hash Type, straight line plot and press Enter.

Type the lines,

set origin 0.5,0.5

set size 0.5, 0.5

Again specify the size and position for this graph.


The position places the graph in top right corner.

Type the lines,

set title "straight line" set xrange[*:*] set yrange[*:*] plot 'data.txt' using 1:3 with linespoint notitle and press Enter.

Enter the commands as seen in on the screen.

Specify the title and autoscale axis range and issue the plot command.

Hover mouse over 1:3 in the plot command. The 3rd column in the data file is the y data values for the straight line plot.
Cursor in gedit window. Pause the video when required to enter the commands.
Hover mouse over origin, xrange and yrange. The stars specify autoscale for axes range.
Hover mouse next to 1:3 .

Hover mouse next to notitle.

Here I am using column 1 for x data and column 3 for y data.

Here I also specify, no legend title is required in the plot.

Cursor in gedit window. Next, let's write the part of script to generate the exponential decay plot.
Type, #Exponential decay and

press Enter.

I will type hash exponential decay for the comment line.
Type,

set origin 0.0,0.5 and press Enter.

For this plot, set the position above the sin x in the top left corner.
Type,

set size 0.5, 0.5 set title "Exponential decay" set autoscale plot 'data.txt' using 1:2 with linespoint notitle and press Enter.

Set size, title for graph and autoscale data.

Read in the columns for x and y data from the data file in the plot command.

Press Enter.

Type unset multiplot and press Enter.

I will leave an blank line after this.

Finally, unset the multiplot mode with the command, unset space multiplot.

Press ctrl+S. Press ctrl S to open the file save as dialogue box.
Type filename as, multiplot.dem

Click on save.

Save the file in Desktop directory with filename multiplot.dem.

Click on save to save the script.

Minimize gedit. Click on save and Minimize the gedit window.
Go to terminal and press Enter. Go to the terminal and press Enter to get the terminal prompt.
Type gnuplot and press Enter. Let’s open gnuplot .
Press Ctrl+L . I will also clear the screen.
Cursor in the terminal. Let's run the script to generate the multiplot.
Type load 'multiplot.dem' and press Enter. Enter the command, load space in single quotes, multiplot.dem.
Show the graphics window with 4 plots. A graphic window with four graphs opens in the canvas.
Show multiplot mode terminal prompt video patch from another terminal.

For this type, multiplot in gnuplot prompt.

In case of errors in the script, gnuplot will remain in the multiplot mode.
Type unset space multiplot and press Enter. Then the graphics plot is also not generated.

If so, type unset space multiplot.

Cursor on the terminal. To reset the default setting, the unset command is used.

If we do not unset the format, the set format will not reset to default setting.


Hover mouse next to gnuplot prompt. This returns the terminal to gnuplot prompt.

If Debug the script to make it error free and run the script to generate the plot.

Go to the graphics window. A few formatting modifications could improve the look of the graphs.
Close the graphics window. Hence, I will make the following modifications in the script. next.

Close the graphics window.

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 it further.

Scroll to the sin(x) script part.

Start a new line before plot command.

Scroll to the sin x part of the script.

Let's change the background color of the sin x plot. Start a new line before the plot command.

Type

set object 1 rectangle from graph 0,0 to graph 1,1 behind fillcolor rgb 'cyan' fillstyle solid noborder and press Enter.

To change background color, we will insert an object, in the graph.

Enter the command as seen on the screen.

Hover mouse next to object, cyan and noborder. Here, we set a cyan colored rectangle, without border, for background.
Start a new line after the plot command.

Type, unset object 1 and press Enter.

Start a new line after the plot command.

Unset the cyan background object, as shown here.

Type in the three lines above the plot command line,

set format y "10^{%L}" set xtics rotate set ytics 40000 and press Enter.

Next, For the straight line plot, add modifications on axis formats.

The commands are added before the plot command as shown.

Point mouse to set format y, then to xtics rotate and then ytics 40000. The y axis numbers are large.

So I will change the notation. I will also rotate the x axis tics in the plot label. I also specify the y tics spacing.

Type unset format y . We will unset the y axis format after the plot command is executed.
Scroll down the script file. Next go to the part of exponential decay script .
Before the plot command, type in the three lines,

set format y "10^{%L}" set xtics rotate set ytics 40000 and press Enter.

I will add the same formatting commands, as in the straight line plot.

Notice that, they are added before the plot command.

Type, unset format y after the plot command. Start a new line after plot command and unset the format of y-axis.
Scroll to top of the script. Let's add command to print the graph into an image file.

Scroll up to the top of the script file.

Before the set multiplot line, type,

set terminal svg size 800,800 enhanced font 'Verdana,12'

Type set term to svg as seen before starting the multiplot mode.
Type

set output 'multiplot.svg' and press Enter.

Direct the output to a svg file as seen.

These are done before the multiplot command is executed.

Scroll to the bottom of the script. Scroll to the bottom of script file and unset the output.

This is done after before we unset the multiplot mode.

Type unset output and press Enter. Enter the command unset space output.
Press Ctrl+S and minimize gedit. Press Ctrl-S to save the file and minimize gedit.
Go to the terminal. Go back to the terminal from where gnuplot was opened.

If you had closed gnuplot, please open gnuplot again.

Enter the command load 'multiplot.dem' . Run the updated multiplot.dem script.

Now, the graphics window does not open, since the output is a svg file, .

Enter the command quit. Enter the command quit, to quit gnuplot.
Go to Desktop. Go to Desktop .
Open multiplot.svg file. Open the file, multiplot.svg that is created on the Desktop.

Since the path is Desktop the output file is generated in the Desktop directory.

Cursor on the svg file. You may add commands to the script file to generate the desired output.
Close the image file. Similar scripts are available in the gnuplot demo website.

Practice and familiarize with the commands and styles. I will close the image file.

Slide Number 6

Summary

Now, to summarize, in this tutorial, we * Learned the multiplot command
  • Defined placement and size of plot in canvas
  • Generated four plots in a canvas
  • Added a rectangle object
  • Generated output on the screen and
  • Generated a svg image file output
Slide Number 7

Assignment 1

For assignment activity, please do the following.
  • Plot 4 parabolas opening to 4 different quadrants in a 2 x 2 multiplot.
  • Give a different background color for each plot.
Slide Number 8

Assignment 2

With the data.txt, provided, do the following.* Generate one plot covering the canvas with x-y1 data points.
  • Draw an inset graph, with x-y2 data points.
Show assignment result screenshot. Completed assignment looks similar to this.
Slide Number 9

Spoken Tutorial Project

This video summarises the Spoken Tutorial Project .

Please download and watch it.

Slide Number 10

Spoken Tutorial workshops

We conduct workshops and give certificates.

For more details, please write to us.

Slide Number 11

Forum for specific questions:

Post your timed queries in the forum.
Slide Number 12

Acknowledgement

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