Gnuplot/C2/Multiple-plots-in-a-canvas/English

From Script | Spoken-Tutorial
Revision as of 14:55, 8 March 2019 by Ranipv076 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
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 multiplot graph via script
  • Define placement and size of graphs in canvas
  • Generate interactive output and file for printing or sharing
Slide Number 3

Pre-requisites

To record this tutorial, I am using,
  • Debian linux 9.3
  • Gedit text editor 3.22
  • And gnuplot 5.2.5
Slide Number 4

System and Software Requirement

To follow this tutorial, learners must be familiar with,

Basic computer and internet skills Concept of graphing and College level Mathematics skills

Multiplot command allow us to plot multiple graphs in a single plotting canvas.

I will demonstrate with four separate graphs in one canvas

Press ctrl alt t

cd Desktop

Press control alt t keys together to open a terminal.

Change to Desktop directory.

Gedit

press enter

Type gedit and press enter, to open gedit.

We will write the commands in a text file and run the script file to plot graph.

I will use gedit text editor, windows users may use notepad software.

We can edit the script file to make any required changes in the graph.

# my first multiplot and press enter I will type hash my first multiplot and press enter

This is a comment line

Next, type the commands as seen in the video.

I will explain them to you.

set multiplot, press enter First, set the environment to multiplot as set space multiplot

Start a new 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

Enter the commands, as seen in the video to specify placement and size
Highlight and type

set origin 0,0

set size 0.5, 0.5

The plot is set in position 0 , 0 in origin

Here I am specifying plot size to be a square of point 5 by point 5

Highlight and type,

set xrange[-10:10]

set yrange[-2:2]

set title '”x-sin(x) plot”

plot sin(x)

Next, we will set x and y range, and title

Then, issue the plot command.

Type,

# x-cos (x) plot

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

First, write a comment to indicate it is the part of the script for cos x. Type hash x cos x plot. Press enter.

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 commands as seen in the video.

When necessary, pause the video. Here, I specify the position and size of the second plot. Set position of the plot to the right of x sin x plot.

For third and fourth plots, I will use the data from a text file.

It is named ‘’’data dot txt’’’ and saved in the desktop directory for me. The file is also provided to you with the tutorial.

Type

#straight line plot

Now, I will enter details for the third plot.

Make a comment, starting with a hash. 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

set size 0.5, 0.5

set title "straight line"

set xrange[*:*]

set yrange[*:*]

plot 'data.txt' using 1:3 with linespoint notitle

Enter commands as seen in video.

Please pause the video when required. Enter the formatting properties for the plot.

Hover mouse over origin, xrange and yrange The stars specifies auto scale for axis range.

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.

Next, let's write script to generate the exponential decay plot.
Type, #Exponential decay I will type hash exponential decay for the comment.
set origin 0.0,0.5 Set position to top left, above the sin x plot

Set size and title for the graph.

set size 0.5, 0.5

set title "Exponential decay"

set autoscale

plot 'data.txt' using 1:2 with linespoint notitle

I will also autoscale the data for axis range.

I will read the x and y data from the data file in the plot command Here, column one and column two are used for x y data.

>unset multiplot Finally, unset the multiplot mode with command, unset space multiplot
Press ctrl-S Press ctrl-S to open the file save dialogue box.
Type filename, multiplot.dem

click on save

I will give file name multiplot dot dem and choose Desktop directory for path.

Click on save to save the script

Minimize gedit

open terminal

Click to minimize gedit.

Let's open another terminal.

Ctrl alt t Press control atl t keys together to open a terminal


cd Desktop” Change directory to desktop
Type, gnuplot

Press enter

Open gnuplot from this terminal
Press control shift k. I will clear the screen and bring prompt to top of the screen for clarity in video.

Let's run the script to generate the multiplot.

load 'multiplot.dem'

Press enter

Type load space in single quotes, multiplot dot dem

Press enter

A graphics window with four graphs in the canvas opens.

I notice a few formatting modifications could improve the view.

Close the graphics window. Hence, make the modifications in the script next.

Close the graphics window.

Go back to gedit script Go back to gedit to edit the script.

If you had closed it, please open the script file to edit it further.

Let's change the background color of the sin x plot.
set object 1 rectangle from graph 0,0 to graph 1,1 behind fillcolor rgb 'cyan' fillstyle solid noborder Scroll to the sin x script and start a new line before the plot command.

To change background color, we will insert an object, in the graph. Enter the command as seen in the video.

Hover mouse next to cyan and noborder Here, we set a rectangle object, with cyan color for background, without border.
unset object After the plot command unset the object

Type, unset space object

set format y "10^{%L}"

set xtics rotate

set ytics 40000

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

Enter the commands as seen in the video.

Hover mouse over the change. The y axis numbers are large.

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

unset format y Unset y axis format after the plot command is executed.
Next, go to the exponential decay part.
set format y "10^{%L}"

set xtics rotate

set ytics 40000

Add the formatting commands, before the plot command as seen on the screen
This specifies y axis label format and rotates x axis label

Set y tics spacing to forty thousand.

Type, unset format y Start a new line after plot command.

Enter command unset space format space y to unset y axis format.

Now let’s add command to print the graph to an image file. Scroll up to the top of the script.
set terminal svg size 800,800 enhanced font 'Verdana,12'

set output 'multiplot.svg'

Set terminal to svg as seen in the video.

Svg is scalable vector graphics.

Direct the output to a svg file

This is done before the multiplot command is executed

unset output

ctrl s

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

>load 'multiplot.dem' Press enter

Minimize gedit.

Go back to terminal where gnuplot was open. Run the updated multiplot dot dem script.

If you had closed gnuplot, please open gnuplot again

This time, the output is directed to a file. The graphics window does not open. The output file is generated in the Desktop directory.

In case of errors in the script, gnuplot may remain in multiplot mode.

If so, type unset space multiplot This returns to gnuplot prompt

Go to Desktop Go to Desktop
Open multiplot.svg Double click on the multiplot dot svg file icon to view it.
You may add desired formatting to the script file.

Notice the cyan background only in the the x sin x plot

Similar scripts are available in gnuplot demo website.

I encourage you to practice and familiarize with commands and styles.

Slide Number 5

Summary

Now, to summarize, in this tutorial, we
  • Learned multiplot command
  • Learned to define placement and size of graph in canvas
  • Wrote, modified and executed script
  • Generated four plots in a canvas
  • Generated interactive output and
  • Generated an image output
Slide Number 6

Assignment

For assignment activity, please do the following.

Plot 4 parabolas opening in 4 different quadrants, in a 2 by 2 multiplot

Slide Number 7

Spoken Tutorial Project

This video summarises the Spoken Tutorial Project

Please download and watch it.

Slide Number 8

Spoken Tutorial workshops

We conduct workshops and give certificates.

Please write to us.

Slide Number 9

Forum for specific questions:

Post your timed queries in the forum.
Slide Number 10

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