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

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(5 intermediate revisions by 4 users not shown)
Line 5: Line 5:
 
|-
 
|-
 
|| '''Slide Number 1'''
 
|| '''Slide Number 1'''
 +
 
'''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'''.
Line 11: Line 13:
 
|-
 
|-
 
|| '''Slide Number 2'''
 
|| '''Slide Number 2'''
 +
 
'''Learning Objectives'''
 
'''Learning Objectives'''
 
|| In this tutorial we will learn to,
 
|| In this tutorial we will learn to,
Line 19: Line 22:
 
|-
 
|-
 
|| '''Slide Number 3'''
 
|| '''Slide Number 3'''
 +
 
'''Learning Objectives'''
 
'''Learning Objectives'''
 
||
 
||
Line 27: Line 31:
 
|-
 
|-
 
|| '''Slide Number 4'''
 
|| '''Slide Number 4'''
 +
 
'''Pre-requisites'''
 
'''Pre-requisites'''
 
|| To record this tutorial, I am using,  
 
|| To record this tutorial, I am using,  
Line 36: Line 41:
 
|-
 
|-
 
|| '''Slide Number 5'''
 
|| '''Slide Number 5'''
 +
 
'''System and Software Requirement'''
 
'''System and Software Requirement'''
 +
 
[https://spoken-tutorial.org/ https:spoken-tutorial.org]
 
[https://spoken-tutorial.org/ https:spoken-tutorial.org]
 
|| To follow this tutorial,  
 
|| To follow this tutorial,  
Line 43: Line 50:
  
 
|-
 
|-
|| '''Slide Number 5'''
+
|| '''Slide Number 6'''
 +
 
 
'''Code files'''
 
'''Code files'''
 
||  
 
||  
Line 51: Line 59:
 
|-
 
|-
 
|| Press '''Ctrl+Alt+T'''.
 
|| Press '''Ctrl+Alt+T'''.
 +
 
Enter the command '''cd Desktop'''.
 
Enter the command '''cd Desktop'''.
 
|| Open a '''terminal''' and change the directory to '''Desktop'''.
 
|| Open a '''terminal''' and change the directory to '''Desktop'''.
Line 75: Line 84:
 
|-
 
|-
 
|| Type, '''#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.
Line 193: Line 202:
 
and press '''Enter'''.
 
and press '''Enter'''.
 
|| Enter the commands as shown here.
 
|| Enter the commands as shown here.
 +
 
Specify the title, autoscale axis range and issue the plot command.
 
Specify the title, autoscale axis range and issue the plot command.
  
Line 205: Line 215:
 
|-
 
|-
 
|| Hover mouse over '''origin''', '''xrange''' and '''yrange'''.
 
|| Hover mouse over '''origin''', '''xrange''' and '''yrange'''.
|| The stars specify autoscale for axes range.
+
|| Here, I am specifying autoscale for axes range.
  
 
|-
 
|-
Line 251: Line 261:
 
|-
 
|-
 
|| Press '''ctrl+S'''.
 
|| Press '''ctrl+S'''.
|| Press '''ctrl S''' to open the file '''save as''' dialogue box.
+
|| Press '''ctrl S''' to open the file '''save as''' dialog box.
  
 
|-
 
|-
Line 270: Line 280:
 
|-
 
|-
 
|| Type '''gnuplot''' and press '''Enter'''.
 
|| Type '''gnuplot''' and press '''Enter'''.
|| Let’s open '''gnuplot''' .
+
|| Let’s open '''gnuplot'''.
  
 
|-
 
|-
Line 300: Line 310:
 
|| Cursor on the '''terminal'''.
 
|| Cursor on the '''terminal'''.
 
|| To '''reset''' default setting, the '''unset''' command is used.
 
|| To '''reset''' default setting, the '''unset''' command is used.
If we do not '''unset''' the format, the set format will not '''reset''' to
 
default setting.
 
  
 +
If we do not '''unset''' the format, the set format will not '''reset''' to default setting.
 
|-
 
|-
 
|| Hover mouse next to '''gnuplot''' prompt.
 
|| Hover mouse next to '''gnuplot''' prompt.
Line 316: Line 325:
 
|| Close the graphics window.
 
|| Close the graphics window.
 
|| Hence, I will make the following modifications in the script.
 
|| Hence, I will make the following modifications in the script.
 +
 
Close the graphics window.
 
Close the graphics window.
  
Line 321: Line 331:
 
|| Go back to '''gedit''' script.
 
|| Go back to '''gedit''' script.
 
|| Go back to the '''gedit''' window 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.
 
|| Scroll to the '''sin(x)''' script part.
 +
 
Start a new line before plot command.
 
Start a new line before plot command.
 
|| Scroll to the '''sin x''' part of the script.  
 
|| Scroll to the '''sin x''' part of the script.  
 +
 
Let's change the background color of the '''sin x''' plot.
 
Let's change the background color of the '''sin x''' plot.
  
Line 336: Line 349:
 
and press '''Enter'''.
 
and press '''Enter'''.
 
|| To change the background color, we will insert an object, in the graph.
 
|| To change the background color, we will insert an object, in the graph.
 +
 
Enter the command as seen on the screen.
 
Enter the command as seen on the screen.
  
 
|-
 
|-
 
|| Hover mouse next to '''object,''' '''cyan''' and '''noborder'''.
 
|| Hover mouse next to '''object,''' '''cyan''' and '''noborder'''.
|| Here, we set a cyan colored rectangle, without border, for the background.
+
|| Here, we have set a cyan colored rectangle, without border, for the background.
  
 
|-
 
|-
 
|| Start a new line after the '''plot''' command.
 
|| Start a new line after the '''plot''' command.
 +
 
Type,''' unset object 1''' and press '''Enter'''.
 
Type,''' unset object 1''' and press '''Enter'''.
 
|| Start a new line after the '''plot''' command.
 
|| Start a new line after the '''plot''' command.
 +
 
'''Unset''' the cyan background object, as shown here.
 
'''Unset''' the cyan background object, as shown here.
  
Line 355: Line 371:
 
and press '''Enter'''.
 
and press '''Enter'''.
 
|| For the straight line plot, add modifications on axis formats.
 
|| For the straight line plot, add modifications on axis formats.
 +
 
The y axis numbers are large.  
 
The y axis numbers are large.  
  
Line 373: Line 390:
 
|-
 
|-
 
|| Scroll down the script file.
 
|| Scroll down the script file.
|| Next go to the part of the '''exponential decay''' script .
+
|| Next go to the part of the '''exponential decay''' script.
  
 
|-
 
|-
Line 380: Line 397:
 
'''set xtics rotate '''
 
'''set xtics rotate '''
 
'''set ytics 40000 '''
 
'''set ytics 40000 '''
and press '''Enter'''.
+
 
 +
Press '''Enter'''.
 
|| I will add the same formatting commands, as shown in the straight line plot.
 
|| I will add the same formatting commands, as shown in the straight line plot.
 +
 
Notice that, they are added before the '''plot''' command.
 
Notice that, they are added before the '''plot''' command.
  
Line 391: Line 410:
 
|| Scroll to top of the script.
 
|| Scroll to top of the script.
 
|| Let's add commands to print the graph into an image file.
 
|| Let's add commands to print the graph into an image file.
 +
 
Scroll up to the top of the script file.
 
Scroll up to the top of the script file.
  
Line 402: Line 422:
 
'''set output 'multiplot.svg'''' and press '''Enter'''.
 
'''set output 'multiplot.svg'''' and press '''Enter'''.
 
|| Direct the output to a '''svg''' file as seen.
 
|| Direct the output to a '''svg''' file as seen.
 +
 
These are done before the '''multiplot''' command is executed.
 
These are done before the '''multiplot''' command is executed.
  
Line 407: Line 428:
 
|| Scroll to the bottom of the script.
 
|| Scroll to the bottom of the script.
 
|| Scroll to the bottom of script file and '''unset''' the '''output'''.
 
|| Scroll to the bottom of script file and '''unset''' the '''output'''.
 +
 
This is done after before we '''unset''' the '''multiplot''' mode.
 
This is done after before we '''unset''' the '''multiplot''' mode.
  
Line 415: Line 437:
 
|-
 
|-
 
|| Press '''Ctrl+S '''and minimize '''gedit'''.
 
|| Press '''Ctrl+S '''and minimize '''gedit'''.
|| Press '''Ctrl-S''' to '''save''' the file and minimize '''gedit'''.
+
|| Press '''Ctrl+S''' to '''save''' the file and minimize '''gedit'''.
  
 
|-
 
|-
 
|| Go to the '''terminal'''.
 
|| Go to the '''terminal'''.
 
|| Go back to the '''terminal''' from where '''gnuplot''' was opened.
 
|| Go back to the '''terminal''' from where '''gnuplot''' was opened.
 +
 
If you had closed '''gnuplot''', please open '''gnuplot''' again.
 
If you had closed '''gnuplot''', please open '''gnuplot''' again.
  
Line 425: Line 448:
 
|| Enter the command '''load 'multiplot.dem'''' .
 
|| Enter the command '''load 'multiplot.dem'''' .
 
|| Run the updated '''multiplot.dem''' script.
 
|| Run the updated '''multiplot.dem''' script.
 +
 
Now, the graphics window does not open, since the output is a '''svg''' file.
 
Now, the graphics window does not open, since the output is a '''svg''' file.
  
Line 433: Line 457:
 
|-
 
|-
 
|| Go to '''Desktop'''.
 
|| Go to '''Desktop'''.
|| Go to '''Desktop''' .
+
|| Go to '''Desktop'''.
  
 
|-
 
|-
 
|| Open '''multiplot.svg''' file.
 
|| Open '''multiplot.svg''' file.
 
|| Open the file, '''multiplot.svg''' that is created on the '''Desktop'''.
 
|| 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.
 
Since the path is '''Desktop''' the output file is generated in the '''Desktop''' directory.
  
Line 447: Line 472:
 
|| Close the image file.
 
|| Close the image file.
 
|| Similar scripts are available in the '''gnuplot''' demo website.
 
|| Similar scripts are available in the '''gnuplot''' demo website.
 +
 
Practise and familiarize with the commands and styles.
 
Practise and familiarize with the commands and styles.
 
  
 
|-
 
|-
|| '''Slide Number 6'''
+
|| '''Slide Number 7'''
 +
 
 
'''Summary'''
 
'''Summary'''
 
|| Now, to summarize, in this tutorial, we  
 
|| Now, to summarize, in this tutorial, we  
Line 462: Line 488:
  
 
|-
 
|-
|| '''Slide Number 7'''
+
|| '''Slide Number 8'''
 +
 
 
'''Assignment 1'''
 
'''Assignment 1'''
 
|| For assignment activity, please do the following.
 
|| For assignment activity, please do the following.
Line 470: Line 497:
  
 
|-
 
|-
|| '''Slide Number 8'''
+
|| '''Slide Number 9'''
 +
 
 
'''Assignment 2'''
 
'''Assignment 2'''
 
|| With the file '''data.txt''', that is provided, do the following.
 
|| With the file '''data.txt''', that is provided, do the following.
Line 481: Line 509:
  
 
|-
 
|-
|| '''Slide Number 9'''
+
|| '''Slide Number 10'''
 +
 
 
'''Spoken Tutorial Project'''
 
'''Spoken Tutorial Project'''
 
|| This video summarises the '''Spoken Tutorial Project''' .
 
|| This video summarises the '''Spoken Tutorial Project''' .
Line 487: Line 516:
  
 
|-
 
|-
|| '''Slide Number 10'''
+
|| '''Slide Number 11'''
 +
 
 
'''Spoken Tutorial workshops'''
 
'''Spoken Tutorial workshops'''
 
|| We conduct workshops and give certificates.  
 
|| We conduct workshops and give certificates.  
Line 493: Line 523:
  
 
|-
 
|-
|| '''Slide Number 11'''
+
|| '''Slide Number 12'''
 +
 
 
'''Forum for specific questions:'''
 
'''Forum for specific questions:'''
 
|| Post your timed queries in the '''forum'''.
 
|| Post your timed queries in the '''forum'''.
  
 
|-
 
|-
|| '''Slide Number 12'''
+
|| '''Slide Number 13'''
 +
 
 
'''Acknowledgement'''
 
'''Acknowledgement'''
 
|| '''Spoken Tutorial Project''' is funded by '''MHRD''', '''Government of India'''.
 
|| '''Spoken Tutorial Project''' is funded by '''MHRD''', '''Government of India'''.

Latest revision as of 12:17, 20 April 2023

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
  • 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
  • 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 the basics of gnuplot.
  • For pre-requisite tutorials, please visit this site.
Slide Number 6

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 &. Type gedit space ampersand.

The ampersand makes the process run in the background.

It detaches the process from the terminal.


Press Enter. Press Enter to open gedit.

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 graphs.
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 as shown here.

They 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”

We will set x and y range and title for the sin (x) plot.

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

Type plot sin(x) and press Enter. We will then issue the plot command for sin(x).
Type,

# cos (x) - x plot

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 shown here.

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.

Show screenshot of file on Desktop. 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 the 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.

This position places the graph in the 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 shown here.

Specify the title, 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. Here, I am specifying 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. 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 plot 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 auto-scale the data.

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

Here, it is column 1 and column 2 for x and y data.

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 dialog 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. Minimize the gedit window.
Go to the terminal. Go to the terminal.
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 appear in the canvas.
Show multiplot mode terminal prompt video patch from another terminal. 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 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.

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.

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 the 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 have set a cyan colored rectangle, without border, for the 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.

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

The y axis numbers are large.

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.

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 the exponential decay script.
Before the plot command, type in the three lines,

set format y "10^{%L}" set xtics rotate set ytics 40000

Press Enter.

I will add the same formatting commands, as shown 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 commands 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 to generate the desired output.
Close the image file. Similar scripts are available in the gnuplot demo website.

Practise and familiarize with the commands and styles.

Slide Number 7

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
  • Saved the output to a svg file
Slide Number 8

Assignment 1

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

Assignment 2

With the file data.txt, that is 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. The completed assignment looks similar to this.
Slide Number 10

Spoken Tutorial Project

This video summarises the Spoken Tutorial Project .

Please download and watch it.

Slide Number 11

Spoken Tutorial workshops

We conduct workshops and give certificates.

For more details, please write to us.

Slide Number 12

Forum for specific questions:

Post your timed queries in the forum.
Slide Number 13

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