Interview Questions On Gnuplot Programming For Freshers
Q – 1 Explain about gnuplot functionality?
Ans- ► Plotting two-dimensional functions and data points in many different styles (points, lines, error bars)
► Plotting three-dimensional data points and surfaces in many different styles (contour plot, mesh)
► Algebraic computation in integer, float and complex arithmetic
► User-defined functions and hot-keys
► Support for a large number of operating systems, graphics file formats and output devices
► Extensive on-line help
► TEX-like text formatting for labels, titles, axes, data points
► Interactive command line editing and history (most platforms)
Q – 2 How to include Gnuplot graphs in word processor?
Ans- Basically, you save your plot to a file in a format your word processor can understand (using set term and set output, see above), and then you read in the plot from your word processor. Vector formats (PostScript, emf, svg, pdf, TEX, LATEX, etc) should be preferred, as you can scale your graph later to the right size.
Details depend on which word processor you use; use set term to get a list of available file formats.
Many word processors can use Encapsulated PostScript for graphs. This can be generated by the set terminal postscript eps [color] command. Note that it is a good idea to check and correct the bounding box of the graphs in the eps files (manually or by the fixbb script from gnuplot webpage), as you have to correct this box for any eps figure produced by whichever program.
Some (most?) word processors do not preview the actual image in the eps file, and you have to add the preview image yourself. You can use the GSView viewer for this (available for OS/2, Windows and X11), or some Unix ps tool. Note that the preview image increases size of the eps file; the smallest increase you may get by choosing Tiff 6 Packbits.
Q – 3 How to generate plots in GIF format?
Ans- GIF support is provided by an external library, libgd (http://www.libgd.org). Old versions of gd (versions 1.2 to 1.4) produce only GIF output. Versions 1.6 to 2.0.27 did not support GIF output because of patent concerns.
However versions 1.6 and newer support PNG outputs, and 1.7 and newer support JPEG outputs. Version 2.0.28 of the Boutell gd library restored GIF functionality, and 2.0.29 added support for GIF animation. If your installation of gnuplot is linked to the gd library, you will get support for whatever formats (GIF, PNG, JPEG) are in that version of gd.
In any case, it is easy to convert from one format to another. To convert a PNG output into GIF, you can either use the command line (e.g. convert f.png f.gif or nconvert -out gif f.png) or any GUI program. Another possibility is to output the image as (encapsulated) postscript and convert (export) it into GIF or PNG by ghostscript, e.g. convert -density 150 f.eps f.gif or by any ghostscript-based GUI like gsview, gv or kghostview.
Q – 4 How to print out graphs in Gnuplot?
Ans- The kind of output produced is determined by the set terminal command; for example, set terminal postscript will produce the graph in PostScript format. Output can be redirected using the set output command.
As an example, the following prints out a graph of sin(x) on a Unix machine running the X-Window System.
gnuplot> plot [-6:6] sin(x)
gnuplot> set terminal postscript
Terminal type set to ‘postscript’
Options are ‘landscape monochrome “Courier” 14’
gnuplot> set output “sin.ps”
gnuplot> replot
gnuplot> set output # set output back to default
gnuplot> set terminal x11 # ditto for terminal type
gnuplot> ! lp -ops sin.ps # print PS File (site dependent)
request id is lprint-3433 (standard input)
lp: printed file sin.ps on fg20.rz.uni-karlsruhe.de (5068 Byte)
!
gnuplot>
Using the platform-independent way of restoring terminal by set term push/pop commands, do it by
gnuplot> set terminal postscript eps color lw 15 “Helvetica” 20
gnuplot> set out ‘a.eps’
gnuplot> replot
gnuplot> set term pop
The command set term pop without a previous corresponding set term push switches the terminal back to the startup terminal, e.g. x11, pm or win.
In MS Windows you can click in the upper left corner of the graph window and print directly from there.
Q – 5 Can we animate graphs in Gnuplot?
Ans- First have a look at animate.dem in the demo directory of gnuplot. Basically, animated graphs are a sequence of plots in a suitable format.
If your installation of gnuplot is linked with gd 2.0.29 or newer (see previous entry), the gif terminal can generate directly an animated GIF.
Otherwise, have a look at the tool whirlgif 3.04, available at http://www.danbbs.dk/ dino/whirlgif. It reads run-length encoded GIF files and packs them into a minimal animation. On the web-pages you will find a manual and an example.
You can also write a small script to get gnuplot to output a family of GIF files, then have it execute some animator such as gifsicle: http://www.lcdf.org/ eddietwo/gifsicle or gifmerge http://the-labs.com/GIFMerge.
mpeg_encode will encode a sequence of images into an mpeg format movie.
Q – 6 How to change symbol size, line thickness and the like in Gnuplot?
Ans- Gnuplot offers a variety of commands to set line and point properties, including color, thickness, point shape, etc. The command test will display a test page for the currently selected terminal type showing the available pre-defined combinations of color, size, shape, etc. The set style command can be used to define additional combinations.
Q – 7 Explain about Gnuplot and why is it called gnuplot?
Ans- The authors of gnuplot are: Thomas Williams, Colin Kelley, Russell Lang, Dave Kotz, John Campbell, Gershon Elber, Alexander Woo and many others.
The following quote comes from Thomas Williams about Gnuplot:
I was taking a differential equation class and Colin was taking Electromagnetics, we both thought it’d be helpful to visualize the mathematics behind them. We were both working as sys admin for an EE VLSI lab, so we had the graphics terminals and the time to do some coding. The posting was better received than we expected, and prompted us to add some, albeit lame, support for file data.
Any reference to GNUplot is incorrect. The real name of the program is “gnuplot”. You see people use “Gnuplot” quite a bit because many of us have an aversion to starting a sentence with a lower case letter, even in the case of proper nouns and titles. gnuplot is not related to the GNU project or the FSF in any but the most peripheral sense.
Our software was designed completely independently and the name “gnuplot” was actually a compromise. I wanted to call it “llamaplot” and Colin wanted to call it “nplot.” We agreed that “newplot” was acceptable but, we then discovered that there was an absolutely ghastly pascal program of that name that the Computer Science Dept. occasionally used. I decided that “gnuplot” would make a nice pun and after a fashion Colin agreed.
Q – 8 Explain Is gnuplot suitable for scripting?
Ans- Yes. Gnuplot can read in files containing additional commands during an interactive session, or it can be run in batch mode by piping a pre-existing file or a stream of commands to stdin. Gnuplot is used as a back-end graphics driver by such higher-level mathematical packages as Octave, and can easily be wrapped in a cgi script for use as a web-driven plot generator.
Q – 9 How to edit or post-process a gnuplot graph?
Ans- This depends on the terminal type you use.
* X11 toolkits: You can use the terminal type fig and use the xfig drawing program to edit the plot afterwards. You can obtain the xfig program from its web site http://www.xfig.org. More information about the text-format used for fig can be found in the fig-package.
You may use the tgif terminal, which creates output suitable for reading within tgif (http://bourbon.cs.umd.edu:8001/tgif/), an interactive 2-D drawing tool under X11.
* You may use the svg terminal (scalable vector graphics), which can be further edited by a svg editor, e.g. Inkscape (http://www.inkscape.org), Sodipodi (http://sodipodi.sourceforge.net), Sketch (http://sketch.sourceforge.net) or Dia (http://www.lysator.liu.se/ alla/dia), or loaded into OpenOffice.org with an on-fly conversion into OO.o Draw primitives.
* PostScript or PDF output can be edited directly by tools such as Adobe Illustrator or Acrobat, or can be converted to a variety of other editable vector formats by the pstoedit package. Pstoedit is available at http://www.pstoedit.net.
Q – 10 How to run gnuplot on your computer?
Ans- Gnuplot is in widespread use on many platforms, including MS Windows, linux, unix, and OSX. The current source code retains supports for older systems as well, including VMS, Ultrix, OS/2, MS-DOS, Amiga, OS-9/68k, Atari ST, BeOS, and Macintosh. Versions since 4.0 have not been extensively tested on legacy platforms.
Please notify the FAQ-maintainer of any further ports you might be aware of.
You should be able to compile the gnuplot source more or less out of the box on any reasonable standard (ANSI/ISO C, POSIX) environment.
Q – 11 What is Gnuplot?
Ans- Gnuplot is a command-driven interactive function plotting program. It can be used to plot functions and data points in both two- and three-dimensional plots in many different formats. It is designed primarily for the visual display of scientific data. gnuplot is copyrighted, but freely distributable; you don’t have to pay for it.