Difference between revisions of "Gnuplot/C2/LaTeX-and-Gnuplot/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(8 intermediate revisions by 2 users not shown)
Line 15: Line 15:
 
* Add '''Latex''' symbols in axis labels
 
* Add '''Latex''' symbols in axis labels
 
* Export the output to a '''Latex''' file
 
* Export the output to a '''Latex''' file
* Open the '''Latex''' compiler file, compile it and generate a pdf file and
+
* Open the '''Latex''' compiler file, compile it, generate a pdf file and
 
* Crop the '''pdf''' file using pdfcrop  
 
* Crop the '''pdf''' file using pdfcrop  
  
Line 25: Line 25:
 
* '''gnuplot''' 5.2.6
 
* '''gnuplot''' 5.2.6
 
* '''Gedit''' 3.18
 
* '''Gedit''' 3.18
* '''TexWorks''' 0.6.3
+
* '''TexWorks''' 0.6.3 and
 
* '''pdfcrop''' 1.38
 
* '''pdfcrop''' 1.38
  
Line 31: Line 31:
 
|| '''Slide Number 4'''
 
|| '''Slide Number 4'''
 
'''System and Software Requirement'''
 
'''System and Software Requirement'''
|| '''Windows''' users need '''Miktex''' and '''ActivePerl 5.28''' to use '''pdfcrop'''.
+
|| '''Windows''' users need '''Miktex''' and '''ActivePerl''' 5.28 to use '''pdfcrop'''.
  
 
|-
 
|-
Line 43: Line 43:
 
|| '''Slide Number 6'''
 
|| '''Slide Number 6'''
 
'''Code Files'''
 
'''Code Files'''
|| The input files used in this tutorial are provided in the '''code files''' link.
+
|| The input files used in this tutorial are provided in the '''Code files''' link.
Please download and extract the file.
+
Please download and extract the files.
  
 
|-
 
|-
 
|| '''Slide Number 7'''
 
|| '''Slide Number 7'''
 
'''Download link'''
 
'''Download link'''
|| Download links for '''texworks, '''Active Perl''' and Miktex''' are shown here.
+
|| Download links for '''texworks, '''Active Perl''' and '''Miktex''' are shown here.
  
 
|-
 
|-
Line 57: Line 57:
 
|-
 
|-
 
|| Show screenshot of '''data.txt'''.
 
|| Show screenshot of '''data.txt'''.
|| The file consists of 3 columns, '''x, y1, y2''' type data.
+
|| The file consists of 3 columns, '''x''', '''y1''', and '''y2''' type data.
  
 
|-
 
|-
|| Press '''Ctrl+Alt+T''' .
+
|| Press '''Ctrl+Alt+T'''.
 
Type '''cd Desktop''' and press '''Enter'''.
 
Type '''cd Desktop''' and press '''Enter'''.
 
|| Please open a '''terminal''' and change the directory to '''Desktop'''.  
 
|| Please open a '''terminal''' and change the directory to '''Desktop'''.  
I will write and save a script here using gedit text editor.
+
 
 +
I will write and save a script here using '''gedit''' text editor.
  
 
|-
 
|-
 
|| Type '''gedit gnuplot-tex.plt &''' and press '''Enter'''.
 
|| Type '''gedit gnuplot-tex.plt &''' and press '''Enter'''.
 
|| Enter the command as seen on the screen to make a script file.
 
|| Enter the command as seen on the screen to make a script file.
'''Ampersand''' detaches the process from the '''terminal'''.
+
 
 +
The '''ampersand''' detaches the process from the '''terminal'''.
  
 
|-
 
|-
 
|| Cursor on '''gedit''' text editor.
 
|| Cursor on '''gedit''' text editor.
|| Let's write the script to plot the 2 graphs on screen.  
+
|| Let's write a script to plot 2 graphs on screen.  
  
 
|-
 
|-
||  
+
|| Cursor in gedit text editor.
 
|| I will plot the 2 sets of data, '''y1''' and '''y2,''' on '''y-axis'''.
 
|| I will plot the 2 sets of data, '''y1''' and '''y2,''' on '''y-axis'''.
  
Line 91: Line 93:
 
|-
 
|-
 
||Type,  
 
||Type,  
'''set boxwidth 1
+
'''set boxwidth 1'''
set tics in
+
 
 +
'''set tics in'''
  
set format y '%0.1e'  
+
'''set format y '%0.1e' '''
  
set xtics  
+
'''set xtics '''
  
set ytics  
+
'''set ytics '''
  
set title "gnuplot and latex" '''
+
'''set title "gnuplot and latex" '''
  
 
and press '''Enter'''.
 
and press '''Enter'''.
Line 107: Line 110:
 
|-
 
|-
 
|| Type,  
 
|| Type,  
'''set xlabel "$\\beta_u^2$ values"
+
'''set xlabel "$\\beta_u^2$ values" '''
  
set ylabel "$\\sigma_y^2$" '''
+
'''set ylabel "$\\sigma_y^2$" '''
  
 
and press '''Enter'''.
 
and press '''Enter'''.
Line 121: Line 124:
 
|-
 
|-
 
|| Type,  
 
|| Type,  
'''plot "data.txtgraph.dat" using 1:2 title 'Y1''''
+
'''plot "data.txt" using 1:2 title 'Y1''''
  
 
and press '''Enter'''.
 
and press '''Enter'''.
Line 130: Line 133:
 
'''pause -1 “Press enter to continue”'''
 
'''pause -1 “Press enter to continue”'''
 
and press '''Enter'''.
 
and press '''Enter'''.
|| Next, type the '''pause -1''' command line as seen on the screen.
+
|| Type the '''pause -1''' command line as seen on the screen.
  
 
The '''pause''' command suspends the script and waits for a user input.
 
The '''pause''' command suspends the script and waits for a user input.
Line 136: Line 139:
 
The '''-1''' refers to the user input, which require the user to press the '''Enter''' key.
 
The '''-1''' refers to the user input, which require the user to press the '''Enter''' key.
  
The text '''press enter to continue''' is also displayed on the screen.
+
The text '''press Enter to continue''' is also displayed on the screen.
  
 
|-
 
|-
 
|| Type,  
 
|| Type,  
'''set ticslevel 0.5
+
'''set ticslevel 0.5'''
  
set boxwidth 1
+
'''set boxwidth 1'''
  
set format y '%0.2e' '''
+
'''set format y '%0.2e' '''
  
 
and press '''Enter'''.
 
and press '''Enter'''.
Line 153: Line 156:
 
|| Type, '''set title "gnuplot-tex integration"
 
|| Type, '''set title "gnuplot-tex integration"
  
set xlabel "$\\beta_u^2$ values"
+
'''set xlabel "$\\beta_u^2$ values" '''
  
set ylabel "$\\sigma_y^2$" '''
+
'''set ylabel "$\\sigma_y^2$" '''
  
 
and press '''Enter'''.
 
and press '''Enter'''.
Line 171: Line 174:
 
'''pause -1 “Press return to continue”'''
 
'''pause -1 “Press return to continue”'''
 
and press '''Enter'''.
 
and press '''Enter'''.
|| Again, enter the command '''pause -1''', with '''press return to continue''' at the prompt.
+
|| Again, enter the pause command, '''pause -1''', with '''Press Enter to continue''' at the prompt.
  
 
|-
 
|-
|| Press '''Ctrl+S''' and press '''Enter'''.
+
|| Click on the Save button.  
Type '''gnuplot''' and press '''Enter'''.
+
 
|| I will save the file.
 
|| I will save the file.
Minimize '''gedit''' and go back to the '''terminal'''.
+
Click on the save button on the top right corner.
  
Open '''gnuplot''' from the '''terminal'''.
+
|-
 +
|| Minimize '''gedit''' and go to  the '''terminal'''.
 +
|| Minimize '''gedit''' and go back to the '''terminal'''.
  
 
|-
 
|-
|| Press '''Ctrl + Shift + K'''.
+
|| Type '''gnuplot''' and press '''Enter'''.
 +
||Open '''gnuplot''' from the '''terminal'''.
 +
 
 +
|-
 +
|| Press '''Ctrl + L.
 
|| I will also clear the screen.
 
|| I will also clear the screen.
  
Line 191: Line 199:
 
|-
 
|-
 
|| Hover mouse over the axis labels.
 
|| Hover mouse over the axis labels.
|| Notice the first plot has axis labels.
+
|| Notice the plot has axis labels.
 
They are in '''Latex''' format, we will compile later on in this tutorial.
 
They are in '''Latex''' format, we will compile later on in this tutorial.
  
 
|-
 
|-
 
|| Press '''Enter''' in the '''terminal'''.
 
|| Press '''Enter''' in the '''terminal'''.
|| The terminal prompt reads, '''press enter to continue'''.
+
|| The terminal prompt reads, '''Press Enter to continue'''.
 +
 
 
Press '''Enter''' in the '''terminal''' and notice the second plot.
 
Press '''Enter''' in the '''terminal''' and notice the second plot.
  
 
|-
 
|-
 
|| Cursor on graphical window.
 
|| Cursor on graphical window.
|| Now, I have seen both the plots.  
+
|| You have seen both the plots.  
I want to plot '''y1''' and '''y2''' together in a '''latex''' scaffold to generate a '''tex''' file.
+
 
 +
Let's plot '''y1''' and '''y2''' together in a '''latex''' scaffold to generate a '''tex''' file.
  
 
|-
 
|-
 
|| Press '''Enter''' in the '''terminal'''.
 
|| Press '''Enter''' in the '''terminal'''.
 
|| Again, press '''Enter''' in the '''terminal'''.
 
|| Again, press '''Enter''' in the '''terminal'''.
 +
 
Now we are back on '''gnuplot''' prompt.
 
Now we are back on '''gnuplot''' prompt.
  
Line 234: Line 245:
 
|-
 
|-
 
|| Type,  
 
|| Type,  
'''set xlabel "$\\beta_u^2$"
+
'''set xlabel "$\\beta_u^2$" '''
  
set ylabel "$\\sigma_y^2$" '''
+
'''set ylabel "$\\sigma_y^2$" '''
  
 
and press '''Enter'''.
 
and press '''Enter'''.
Line 252: Line 263:
 
|| For demonstration I will add 3 seconds delay after the pause.
 
|| For demonstration I will add 3 seconds delay after the pause.
  
The message text dipslay would read, '''Now tex file is generated'''.
+
The message text display would read, '''Now tex file is generated'''.
  
 
|-
 
|-
Line 307: Line 318:
 
|-
 
|-
 
|| Type,  
 
|| Type,  
'''\documentclass{article}
+
'''\documentclass{article} '''
  
\usepackage{color}'''
+
'''\usepackage{color}'''
  
 
and press '''Enter'''.
 
and press '''Enter'''.
Line 318: Line 329:
 
|-
 
|-
 
|| Type,
 
|| Type,
'''\setlength{\textwidth}{100cm}
+
'''\setlength{\textwidth}{100cm} '''
  
\setlength{\textheight}{100cm}'''
+
'''\setlength{\textheight}{100cm}'''
  
 
and press '''Enter'''.
 
and press '''Enter'''.
Line 328: Line 339:
 
|| Type,
 
|| Type,
  
''' \begin{document}
+
'''\begin{document}'''
\pagestyle{empty}
+
 
\input{gnuplot.tex}
+
'''\pagestyle{empty}'''
\end{document}'''
+
 
 +
'''\input{gnuplot.tex}'''
 +
 
 +
'''\end{document}'''
  
 
and press '''Enter'''.
 
and press '''Enter'''.
Line 346: Line 360:
  
 
I will give filename as '''bgnuplot dot tex''' and save in the '''Desktop''' folder.
 
I will give filename as '''bgnuplot dot tex''' and save in the '''Desktop''' folder.
 +
 +
|-
 +
|| Click on the '''Save''' button.
 +
|| Click on the '''Save''' button on the bottom right corner.
  
 
|-
 
|-
 
|| Click on the '''typeset''' icon.
 
|| Click on the '''typeset''' icon.
|| Now, click on the '''typeset''' icon or button to generate the '''pdf''' file.
+
|| Now, click on the '''typeset''' icon to generate the '''pdf''' file.
 
A '''pdf''' file appears on the screen.
 
A '''pdf''' file appears on the screen.
  
Line 355: Line 373:
 
|| Hover mouse over Greek symbols, superscript and subscript.
 
|| Hover mouse over Greek symbols, superscript and subscript.
 
|| Now, you have generated the graph integrating '''gnuplot''' and '''latex'''.
 
|| Now, you have generated the graph integrating '''gnuplot''' and '''latex'''.
 +
 
Notice the '''Greek symbols''', superscript and subscript in the '''pdf''' file.
 
Notice the '''Greek symbols''', superscript and subscript in the '''pdf''' file.
  
Line 365: Line 384:
 
|| Let's go back to the '''terminal'''.
 
|| Let's go back to the '''terminal'''.
  
Now, crop this document using the '''pdfcrop'''.
+
Now, crop this document using '''pdfcrop'''.
  
 
|-
 
|-
Line 412: Line 431:
 
|| '''Slide Number 9'''
 
|| '''Slide Number 9'''
 
'''Assignment 1'''
 
'''Assignment 1'''
 +
 +
  
 
|| For assignment activity, practise the exercise learned in this tutorial.
 
|| For assignment activity, practise the exercise learned in this tutorial.
 
* Read the documentation on pause command from the help section.
 
* Read the documentation on pause command from the help section.
* Suspend the script with  
+
* Suspend the script with,
 
* time delay of 10 seconds and  
 
* time delay of 10 seconds and  
 
* with a mouse click.
 
* with a mouse click.

Latest revision as of 15:32, 17 March 2020

Visual Cue Narration
Slide Number 1

Title Slide

Welcome to the tutorial on Latex and gnuplot.
Slide Number 2

Learning Objectives

In this tutorial, we will
  • Learn the pause command to suspend script file execution
  • Add Latex symbols in axis labels
  • Export the output to a Latex file
  • Open the Latex compiler file, compile it, generate a pdf file and
  • Crop the pdf file using pdfcrop
Slide Number 3

System and Software Requirement

To record this tutorial, I am using
  • Ubuntu Linux version 16.04 OS
  • gnuplot 5.2.6
  • Gedit 3.18
  • TexWorks 0.6.3 and
  • pdfcrop 1.38
Slide Number 4

System and Software Requirement

Windows users need Miktex and ActivePerl 5.28 to use pdfcrop.
Slide Number 5

Pre-requisites

To follow this tutorial,
  • Learner must be familiar with the basics of gnuplot and Latex.
  • For prerequisite tutorials please visit this site.
Slide Number 6

Code Files

The input files used in this tutorial are provided in the Code files link.

Please download and extract the files.

Slide Number 7

Download link

Download links for texworks, Active Perl and Miktex are shown here.
Show screenshot of Desktop with graph.dat . I have saved the input file data.txt on the Desktop.
Show screenshot of data.txt. The file consists of 3 columns, x, y1, and y2 type data.
Press Ctrl+Alt+T.

Type cd Desktop and press Enter.

Please open a terminal and change the directory to Desktop.

I will write and save a script here using gedit text editor.

Type gedit gnuplot-tex.plt & and press Enter. Enter the command as seen on the screen to make a script file.

The ampersand detaches the process from the terminal.

Cursor on gedit text editor. Let's write a script to plot 2 graphs on screen.
Cursor in gedit text editor. I will plot the 2 sets of data, y1 and y2, on y-axis.
Type #interactive plot and press Enter. First, I will write a comment line.

Let’s plot x-y1 data.


Type, set terminal x11 and press Enter. I will set the terminal.
Type,

set boxwidth 1

set tics in

set format y '%0.1e'

set xtics

set ytics

set title "gnuplot and latex"

and press Enter.

I will add graph formatting commands and add a title for the plot.
Type,

set xlabel "$\\beta_u^2$ values"

set ylabel "$\\sigma_y^2$"

and press Enter.

Here, we are incorporating latex symbols, beta and sigma in axis labels.

The underscore u, will format the u subscript in latex at a later stage.

The carat 2 creates a superscript for the number two.

Type,

plot "data.txt" using 1:2 title 'Y1'

and press Enter.

Plot x y1 data and specify the legend as Y1.
Type

pause -1 “Press enter to continue” and press Enter.

Type the pause -1 command line as seen on the screen.

The pause command suspends the script and waits for a user input.

The -1 refers to the user input, which require the user to press the Enter key.

The text press Enter to continue is also displayed on the screen.

Type,

set ticslevel 0.5

set boxwidth 1

set format y '%0.2e'

and press Enter.

Next, we will plot x-y2 data.


Type, set title "gnuplot-tex integration"

set xlabel "$\\beta_u^2$ values"

set ylabel "$\\sigma_y^2$"

and press Enter.

I will again add few graph formatting commands.

I will also give a title and incorporate Latex symbols in axis labels.

Type, plot "data.txt" using 1:3 title 'Y2' with line

and press Enter.

Make a plot with the first and the third columns here.
Type,

pause -1 “Press return to continue” and press Enter.

Again, enter the pause command, pause -1, with Press Enter to continue at the prompt.
Click on the Save button. I will save the file.

Click on the save button on the top right corner.

Minimize gedit and go to the terminal. Minimize gedit and go back to the terminal.
Type gnuplot and press Enter. Open gnuplot from the terminal.
Press Ctrl + L. I will also clear the screen.
Type, load 'gnuplot-tex.plt' and press Enter. Let’s load the newly created script file as seen.
Hover mouse over the axis labels. Notice the plot has axis labels.

They are in Latex format, we will compile later on in this tutorial.

Press Enter in the terminal. The terminal prompt reads, Press Enter to continue.

Press Enter in the terminal and notice the second plot.

Cursor on graphical window. You have seen both the plots.

Let's plot y1 and y2 together in a latex scaffold to generate a tex file.

Press Enter in the terminal. Again, press Enter in the terminal.

Now we are back on gnuplot prompt.

Go to the gedit window. Go to the gedit window to edit the script.
Type,

#latex file output and press Enter.

Let's generate a tex file output from gnuplot.

I will add a comment line first mentioning the same.

Type,

set term latex set output "gnuplot.tex" and press Enter.

Set the term to latex and give an output file name.

Here, the output filename is gnuplot dot tex.

This generates a file in tex format.

Type,

set xlabel "$\\beta_u^2$"

set ylabel "$\\sigma_y^2$"

and press Enter.

Here again, Latex symbols are incorporated in axis labels.
Type, plot "data.txt" using 1:2 title 'Y1' , "data.txt" using 1:3 title 'Y2' with linespoint lc 'blue' lw 2 pt 7 ps 1.5

and press Enter.

I will change line, symbol and color properties in the plot command.
Type, pause 3 ‘Now tex file is generated’

and press Enter.

For demonstration I will add 3 seconds delay after the pause.

The message text display would read, Now tex file is generated.

Type reset and press Enter. Type reset, to reset the terminal at the end of the script.
Press Ctrl+S and press Enter.

Type gnuplot and press Enter.

Save the file.

Minimize gedit and go back to the terminal.

Type, load 'gnuplot-tex.plt' and press Enter. Load the script file again.
Press Enter in the terminal. Press Enter in the terminal and notice the second plot.
Press Enter in the terminal. Press Enter again on the terminal, as seen here.
Text message Now text file is generated is displayed on the screen. After the 3 seconds pause, the prompt returns to gnuplot prompt.

The output is a latex file as specified in the script.

Type q and press Enter. Let’s exit gnuplot.
Go to Desktop. Go to Desktop and notice the newly generated tex file.
Open the tex file. Open the file using tex program.

Notice a large file in tex format.

Cursor on the tex file and scroll. We will compile this file with tex and generate a pdf file output.

For this purpose, do the following.

Press Ctrl+N . Open a new blank file from the tex window.
Type,

\documentclass{article}

\usepackage{color}

and press Enter.

Enter the commands as seen on the screen.

We will add header and user package details.

Type,

\setlength{\textwidth}{100cm}

\setlength{\textheight}{100cm}

and press Enter.

Pause the video as and when required.
Type,

\begin{document}

\pagestyle{empty}

\input{gnuplot.tex}

\end{document}

and press Enter.

Next, compile the gnuplot generated file in latex.

Mention the name of the tex file that is to be compiled.

Then, specify to end the document.

Press Control+S to save.

Give file name bgnuplot.tex, in Desktop folder.

Let’s save the file.

I will give filename as bgnuplot dot tex and save in the Desktop folder.

Click on the Save button. Click on the Save button on the bottom right corner.
Click on the typeset icon. Now, click on the typeset icon to generate the pdf file.

A pdf file appears on the screen.

Hover mouse over Greek symbols, superscript and subscript. Now, you have generated the graph integrating gnuplot and latex.

Notice the Greek symbols, superscript and subscript in the pdf file.

Close both tex documents and the pdf file. Close the tex documents and the pdf file.
Go to the terminal. Let's go back to the terminal.

Now, crop this document using pdfcrop.

Press Ctrl+L. I will also clear the screen.
Type pdfcrop bgnuplot.pdf and press Enter. Enter the command, pdfcrop space bgnuplot dot pdf.
Cursor next to pdfcrop. This program crops the margins from the pdf file.

The pdfcrop has named the file with a crop suffix.

Show screenshot accessing pdfcrop in windows. The pdfcrop may look similar to this for Windows users.
Go to Desktop. Go to Desktop again and notice the newly generated cropped file.
View the cropped file. Open the cropped file to view it.
Close the cropped pdf file. I will close this pdf file.
Slide Number 8

Summary

Now let's summarize.

In this tutorial, we

  • Learned the pause command
  • Generated a latex output file
  • Compiled the latex file to generate a pdf file of the graph and
  • Cropped the output pdf file using pdfcrop.
Slide Number 9

Assignment 1


For assignment activity, practise the exercise learned in this tutorial.
  • Read the documentation on pause command from the help section.
  • Suspend the script with,
  • time delay of 10 seconds and
  • with a mouse click.
Slide Number 9

Assignment 2

* Use data file assignment.txt, to generate a graph.
  • You may also use your own choice of dataset.
Slide Number 10

Assignment 2

  • Generate a LaTex output for a gnuplot graph.
  • Compile the file in LaTex and generate a pdf file output.
Glimpse of assignment. Your assignment may look similar to this.
Slide Number 11

Spoken Tutorial Project

This video summarises the Spoken Tutorial Project.

Please download and watch it.

Slide Number 11

Spoken Tutorial workshops

The Spoken Tutorial Project Team
  • conducts workshops and
  • gives 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, Ranipv076