gnuplot Interview Questions & Answers

  1. Question 1. What Is Gnuplot?

    Answer :

    • Gnuplot is an interactive plotting program that is command based.
    • It is used for plotting functions and data points in 2D and 3D plots.
    • Gnuplot supports many formats of data points and functions.
    • It is primarily used for displaying scientific data .
    • It supports 3D data points and surfaces in various styles like contour plot, mesh etc.
  2. Question 2. Which Plat From Supports Gnuplot?

    Answer :

    • Gnuplot supports various OS platforms including Windows, Linux, Unix, OSX.
    • Current version supports even on older operating systems such as MS-DOS,KAmiga, OS-9/68k, Atari ST. 
    • The legacy architecture platforms support versions below 4.0
    • Gnuplot is a freeware authored by freelance authors, volunteers.
    • The compilation of Gnuplot script is different for individual operating systems.
  3. Linux Interview Questions

  4. Question 3. Explain About Gnuplot Functionality?

    Answer :

    Following is the functionality of gnuplot.

    • Two-dimensional functions and data points plotting.
    • Three-dimensional data points and surfaces plotting in contour and mesh styles.
    • Computing algebraic expressions in integer, float and complex arithmetic.
    • User defined hot keys.
    • Extensive online help.
    • Gnuplot supports TEX-like text formatting for data points, axes, titles and labels.
    • Command line editing in user friendly manner.
  5. Question 4. How To Change Symbol Size, Line Thickness And The Like In Gnuplot?

    Answer :

    • Various commands are available to assign line and point properties.
    • These properties include color, thickness, shape of point etc.
    • The command test displays a test page for the selected terminal type.
    • The test page shows all available pre-defined combinations of colors, size and shapes.
    • The command ‘set style’ is used to define the combinations.
  6. Linux Tutorial

  7. Question 5. How To Animate In Gnuplot?

    Answer :

    • Animated graphs are a set of plots.
    • These graphs are available in suitable formats.
    • Version gd 2.0.29 or later supports direct generation of an animated GIF.
    • Scripts can be written to generate output of GIF files.
    • The generated animated GIF files can be executed in animators such as ‘gifsicle’. 
    • The ‘mpeg_encode’ command encodes the sequences of images into mpeg format movies.
  8. Computer Graphics Interview Questions

  9. Question 6. How To Generate Plots In Gif Format?

    Answer :

    • GIF format support is provided by external library of Gnuplot.
    • One such library is ‘libgd’.
    • Versions 1.2 to 1.4 of libgd produces only GIF output.
    • Versions 1.6 to 2.0.27 supports PNG outputs.
    • Version 2.0.28 of Boutell gd library restored the support of GIF functionality.
    • To get the support of GIF, gnuplot need to be linked with any compatible gd library.
  10. Question 7. How To Include Gnuplot Graphs In Word Processor?

    Answer :

    • Usually, save a plot to a word processor format that gnuplot understands.
    • Read the plot from the word processor. 
    • Vector formats like PostScript, pdf, TEX,LATEX etc. are preferred.
    • Vector formats supports scaling the graph later to the correct size.
    • Use ‘set term’ to get available file format list.
    • It is suggested to check and correct the bounding box of the graphs in ‘eps’ file format.
    • Use GSView viewer for previewing the image box.
  11. Computer Graphics Tutorial
    Mac OS X Deployment Interview Questions

  12. Question 8. How To Print Out Graphics In Gnuplot?

    Answer :

    • To print graph, ‘set terminal’ is used. 
    • For example, ‘set terminal postscript’ produces the graph in PostScript format.
    • The out put can be redirected by using ‘set output’ command.

    The following script allows to produce output of a graph sin(x) in PostScript format:

    gnuplot> plot [-6:6] sin(x)
    gnuplot> set terminal postscript
    gnuplot> set output “”
    gnuplot> replot

  13. Question 9. Is Gnuplot Suitable For Scripting?

    Answer :

    • Yes. Gnuplot is suitable for scripting.
    • The scripts can be read by gnuplot during an interactive session.
    • It also runs in batch mode.
    • Running in batch mode is done by piping a pre-existing file.
    • A stream of commands can also be sent to stdin, to run in batch mode.
    • Packages such as Octave is easily wrapped in a cgi script to be used as a web-driven plot generator.
  14. Scalable Vector Graphics Interview Questions

  15. Question 10. Why The Origin Of Z-axis Is Not On The Xy-plane?

    Answer :

    • The zero-point of Z-axis is placed above the XY plane of splot.
    • ‘set ticslevel’ is used to move this origin onto the XY plane.
    • By setting ticslevel=0, the zero of Z-axis moves onto the XY plane.
    • The following is the script to do this:
      gnuplot> set ticslevel 0
      gnuplot> splot (x**2)*(y**2)
  16. Windows 10 Tutorial

  17. Question 11. How To Change Contours In Gnuplot?

    Answer :

    • Contours are controlled by the command ‘set cntrparam’.
    • Following example illustrates change of contours:

      gnuplot> set contour
      gnuplot> set cntrparam levels 12
      gnuplot> set cntrparam levels incremental -1, 0.2, 1
      gnuplot> set cntrparam levels discrete -0.2, -0.5, 0.2, 0.5

    • The key world ‘levels’ defines the levels of drawn contour curves.
    • In the above example, levels 12 indicates that twelve contour lines are drawn.
    • Incremental defines the initial value, increment value and the final value.
    • A legend for contour lines is available in the legend graph.
  18. SAP Enterprise Portal Interview Questions

  19. Question 12. How To Make Surface Mesh Finer?

    Answer :

    • The mesh size, indicated by XY coordinates is determined by ‘isosample’.
    • The default number is 10.
    • To get the finer mesh the size should be more.
    • The mesh size troubles when a hidden line option is used with ‘set hidden3d’.
    • To avoid these troubles, make ‘isosample’ larger, like 30 and above.
  20. Linux Interview Questions

  21. Question 13. How To Plot Implicit Defined Graphs?

    Answer :

    • Implicit graphs are plotted indirectly.
    • The following example illustrates the process:
      gnuplot> function(x,y) = y – x**2 / tan(y)
      gnuplot> set contour base
      gnuplot> set cntrparam levels discrete 0.0
      gnuplot> unset surface
      gnuplot> set table ‘graphcurves.dat’
      gnuplot> splot function(x,y)
      gnuplot> unset table
      gnuplot> plot ‘graphcurves.dat’ w l
    • The function() sets the coordinates.
    • The contour graph is defined in ‘graphcurves.dat’ file.
    • ‘splot’ executes the function.
    • ‘plot’ places the graph in the file ‘graphcurves.dat’ file.
  22. Unix/Linux Tutorial

  23. Question 14. How To Fill An Area Between Two Curves?

    Answer :

    • A pseudo file ‘+’ is used to fill the area between two curves. 
    • The option ‘filledcurves’ closed is used.
    • The following example demonstrates the process. The two curves are f(x) and g(x).
      set xrange [0:xmax]
      plot ‘+’ using 1:(f($1)):(g($1)) with filledcurves closed
  24. Question 15. How To Include Accented Characters?

    Answer :

    • 8 bit character codes are used to obtain accented characters.
    • Example of accented character is ü
    • Following is an example to include accented characters:
      gnuplot> set encoding iso_8859_1
      gnuplot> set title “M374nchner Bierverbrauch 374ber die Jahre”
      gnuplot> plot “bier.dat” u 1:2
    • Like wise, characters in Czech, French, Russia characters can be types using set encoding.
    • Two or more encoding characters can not be mixed in one file. Ex. accents for west and east latin encodings.
    • UTF-8 encoding fonts can be a general solution.
  25. Advanced C# Interview Questions

  26. Question 16. How To Plot Two Functions In Non-overlapping Regions?

    Answer :

    • Parametric plot can be used to plot 2 functions in non-overlapping regions.
    • Following examples illustrates:
      gnuplot> set parametric
      gnuplot> aaf=1
      gnuplot> bb=3
      gnuplot> cc=2
      gnuplot> dd=4
      gnuplot> x1(t) = aa+(bb-aa)*t
      gnuplot> x2(t) = cc+(dd-cc)*t
      gnuplot> f1(x) = sin(x)
      gnuplot> f2(x) = x**2/8
      gnuplot> plot [t=0:1] x1(t),f1(x1(t)) title “f1”, x2(t), f2(x2(t)) title “f2”
    • The last line of code is parametric plot that plots the functions x1 and f1, x2 and f2.
  27. Question 17. How To Produce Graph Of An Exact Border Size?

    Answer :

    • Position the top, left, bottom, right borders in fractional position within the page.
    • The following script set the exact border size.
      set lmargin at screen 0.05
      set bmargin at screen 0.05
      set rmargin at screen 0.95
      set tmargin at screen 0.95
  28. Advanced C++ Interview Questions

  29. Question 18. How To Fix The Bug Of Partial Displaying Of Output Files?

    Answer :

    • Flush the output with a closing set output.
    • Certain output formats like PostScript, PDF,Latex, etc., places many pages in a single resultant file.
    • The file remains open after every plot by gnuplot. So that additional plots can be added to it. 
    • The file is available to the external applications as it is in open state. 
    • As the files are open and remain unclosed, the partial output is plotted.
    • To avoid the issue, specify the term for a plot using ‘set term’.
  30. Computer Graphics Interview Questions

  31. Question 19. How To Call Gnuplot In A Pipe Or With A Gnuplot-script Doesn’t Produce A Plot?

    Answer :

    Gnuplot can be called by using a perl script.

    Following script illustrates:

    #!/usr/local/bin/perl -w
    open (GP, “|/usr/local/bin/gnuplot -persist”) or die “no gnuplot”;
    # force the buffer to flush after every write
    use FileHandle;
    print GP,”set term x11;plot ‘/tmp/data.dat’ with linesn”;
    close GP

  32. Question 20. How To Plot A Vertical Line?

    Answer :

    There are 3 alternatives to plot a vertical line using Gnuplot.

    1. A vertical line can be plotted using ‘set arrow ….. nohead’.
      – The start and end points of an arrow need to be explicitly computed.
    2. Other alternative is to generate the in lined data points and plot them.
    3. Another process is to use parametric mode of gnuplot.
  33. Advanced Linux Interview Questions

  34. Question 21. How Would You Define A Function In Gnuplot?

    Answer :

    In Gnuplot, you can define your own functions. Functions are defined using C programming-style definitions, with the same operators and C math library, functions, with the exception of the **, operator, which is the exponentiation. For your reference, a list of built-in functions and operators are provided here.

    Here is an example of the definition of a sinc function. (The sinc function is defined as the sine of pi times x divided by pi times x, and is used typically in communications applications.)

    sinc(x) = sin(pi * x) / (pi * x)

    The value pi is a predefined value.