Gnuplot/C2/LaTeX-and-Gnuplot/English

From Script | Spoken-Tutorial
Revision as of 17:28, 19 February 2020 by Ranipv076 (Talk | contribs)

Jump to: navigation, search
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 and 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
  • 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 file.

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, 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.

Ampersand detaches the process from the terminal.

Cursor on gedit text editor. Let's write the script to plot the 2 graphs on screen.
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.txtgraph.dat" 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.

Next, 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 command pause -1, with press return to continue at the prompt.
Press Ctrl+S and press Enter.

Type gnuplot and press Enter.

I will save the file.

Minimize gedit and go back to the terminal.

Open gnuplot from the terminal.

Press Ctrl + Shift + K. 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 first 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. Now, I have seen both the plots.

I want to 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$" 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 dipslay 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 typeset icon. Now, click on the typeset icon or button 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 the 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