Difference between revisions of "Gnuplot"

From ConTeXt wiki
(gnOSduEqd)
m (Reverted edits by 208.75.86.111 (Talk) to last version by Mojca Miklavec)
Line 1: Line 1:
NYUzHY  <a href="http://srdnmmxzdgnd.com/">srdnmmxzdgnd</a>, [url=http://cfigwaijdshi.com/]cfigwaijdshi[/url], [link=http://nwsyemomtoyx.com/]nwsyemomtoyx[/link], http://tioihsigsady.com/
+
< [[Modules]] | [[Graphics]] | [[Math]] >
 +
 
 +
http://www.gnuplot.info/figs/title2.png
 +
 
 +
[http://www.gnuplot.info Gnuplot] is a portable command-line driven utility for function plotting for many platforms.
 +
 
 +
To make the examples on this page work, you need a modified binary of Gnuplot (see below).
 +
 
 +
== Minimal Example ==
 +
 
 +
<texcode>
 +
\usemodule[gnuplot]
 +
 
 +
% write a script for gnuplot
 +
\startGNUPLOTscript[sin]
 +
  plot sin(x)
 +
\stopGNUPLOTscript
 +
 
 +
% include the resulting graphic into the document
 +
\useGNUPLOTgraphic[sin]
 +
</texcode>
 +
 
 +
Calling gnuplot to create the graphic and postprocessing should happen automatically.
 +
 
 +
== Requirements ==
 +
 
 +
* '''[http://modules.contextgarden.net/gnuplot Gnuplot module]'''
 +
** in TeX Live you need to have <code>context-gnuplot</code> installed, in [[ConTeXt Minimals]] you can install it with <code>--extras=t-gnuplot</code> switch
 +
* '''Gnuplot has to be installed''' (and in your PATH)
 +
:On most Linux installations this is probably already the case. On Windows you have to create a file <code>gnuplot.bat</code> with something like:
 +
"C:\Program Files\gnuplot\bin\wgnupl32.exe" %*
 +
:and put that file to a <i>"visible place"</i> (has to be found in PATH).
 +
* '''[[write18]]''' has to be enabled
 +
=== To use the ConTeXt terminal (recommended) ===
 +
====  Windows ====
 +
You can take [http://dl.contextgarden.net/modules/gnuplot-win.zip these] binaries from [[modules:gnuplot-win|Modules in the garden]] ''(Note: the binary is old, but I don't have windows any more to compile the latest binary; I can only hope that it still works.)''
 +
====  Unix or Mac ====
 +
The easiest way to fetch and compile the binary is:
 +
git clone git://github.com/mojca/gnuplot.git
 +
./prepare
 +
./configure
 +
make
 +
:''(Alternatively you could download gnuplot source from http://www.gnuplot.info, copy [http://github.com/mojca/gnuplot/raw/master/term/context.trm context.trm] to <code>term/</code>, add <code>#include "context.trm"</code> to <code>src/term.h</code> and follow the same steps for compilation.)''
 +
 
 +
Then replace the old gnuplot executable (once backup-ed) with the one in <code>src/gnuplot</code> or type:
 +
make install
 +
Feel free to contact [[User:Mojca Miklavec|Mojca]] in case of problems.
 +
 
 +
== Creating stand-alone, whole-page plots ==
 +
 
 +
Here's an example of how to make a stand-alone ConTeXt document with one plot per page:
 +
 
 +
set term context standalone size 15cm,10cm header '\usetypescript[iwona][ec]' font 'iwona,ss' 10dd
 +
set output 'example.tex'
 +
plot ...
 +
 
 +
== More complex example ==
 +
 
 +
(I need to change this example to highlight other aspects. Metapost is kind-of-obsolete since ConTeXt terminal was derived from it and produces superior results. But the example below should still be valid.)
 +
 
 +
<texcode>
 +
\usemodule[gnuplot]
 +
 
 +
\setupGNUPLOT[terminal=mp,option=color]
 +
 
 +
% general settings for the whole document
 +
\startGNUPLOTinclusions
 +
 
 +
  # you may use TeX commands to format the titles and axes
 +
  set title '\bf Trigonometry'
 +
  set xlabel '$x$'
 +
  set ylabel '$y$'
 +
 
 +
  # to prevent uneven numbering: will result in
 +
  # (0.0, 0.5, 1.0, 1.5, ...) instead of
 +
  # (0, 0.5, 1, 1.5, ...)
 +
  set format y '\%.1f'
 +
\stopGNUPLOTinclusions
 +
 
 +
\startGNUPLOTscript[tan]
 +
  plot tan(x) t '$\tan(x)$'
 +
\stopGNUPLOTscript
 +
 
 +
\startGNUPLOTscript[sin]
 +
  plot 4*sin(x)+x t '$4\sin(x)+x$', x t '$x$' lt 3
 +
\stopGNUPLOTscript
 +
 
 +
\useGNUPLOTgraphic[tan]
 +
\useGNUPLOTgraphic[sin][width=10cm]
 +
</texcode>
 +
 
 +
== Using other terminals ==
 +
 
 +
<i>(Needs a revision.)</i>
 +
 
 +
Gnuplot support output in different formats with, for example
 +
set terminal mp color solid
 +
will output a metapost document with colors and without dashed lines. After some appropriate preprocessing (with [[MPtoPDF]] for this particular case) this file can be included in PDF documents.
 +
 
 +
You can specify the terminal with
 +
<texcode>
 +
\setupGNUPLOT[terminal=mp,options=color solid]
 +
</texcode>
 +
 
 +
* <code>terminal=</code> is mandatory since that't the only way to tell ConTeXt how to preprocess the file.
 +
* <code>options=</code> is optional and is appended to the end of <code>set terminal [terminal name]</code>. You can also override it by saying
 +
<texcode>
 +
\startGNUPLOTinclusions
 +
set terminal mp color solid
 +
\stopGNUPLOTinclusions
 +
</texcode>
 +
But you have to be careful that you don't set any other terminal with <code>output=</code> then.
 +
 
 +
<!-- Another way to specify it is to override the terminal setting  -->
 +
 
 +
Currently supported terminals are:
 +
* [http://www.gnuplot.info/docs/gnuplot.html#mp mp/metapost]: uses [[MPtoPDF]] to convert images to pdf, but the context terminal should replace it
 +
* [http://www.gnuplot.info/docs/gnuplot.html#postscript_ ps/postscript]: most advanced in the number of supported features
 +
* [http://www.gnuplot.info/docs/gnuplot.html#png_(OLD) png]: outputs bitmap images (no preprocessing needed)
 +
* [http://www.gnuplot.info/docs/gnuplot.html#pdf pdf]: outputs PDF directly (no preprocessing needed), but is usually not available in most binaries of gnuplot
 +
* '''context''':
 +
 
 +
== Development ==
 +
 
 +
* [http://groups.google.com/group/gnuplot-context mailing list]
 +
 
 +
== History ==
 +
 
 +
I ([[User:Mojca Miklavec|Mojca Miklavec]]) probably mentioned long time ago that I would like to have (or write?) support for Gnuplot inside ConTeXt, but I had no knowledge to do that. Peter Münster posted the very first module for gnuplut support on the mailing list [http://article.gmane.org/gmane.comp.tex.context/24884], but that version only worked with bash. In the days to follow Hans Hagen has written a new module (based on my numerous "possible and impossible" requests) and Taco additionally provided some bugfixes and minor changes.
 +
 
 +
The module provides an option to select the most appropriate/suitable driver according to the user's choice (metapost, png, pdf, postscript were the firs ones to be supported). Hans was wondering why there was no '''context terminal'''. I took over it's development, the code is almost finished by now, but I guess that Hans now regrets that question already.
 +
 
 +
He had to invest quite some time into fixing buggy inclusion of text into graphics using <code>textext</code> (if nothing else, he had to read and reply to all the mails [complaints] that me and Taco sent him), just to lead to the conclusion that <code>textext</code> was useless for graphics produced by Gnuplot: too slow and TeX ran out of memory after 10 minutes while processing approximately the 13<sup>th</sup> plot. After that the new marvellous <code>\sometxt</code> command was born.
 +
 
 +
I'm currently sticking tiny pieces together in the way I want the module to work. Hans could probably finish the same work that costs me a few days in a few minutes, but after dropping me a bone, he decided to leave me the joy of diving into ConTeXt internals and to let me figure out how to program in ConTeXt by myself. So I still keep spamming the mailing list with numerous questions and both Taco and Hans - without whom implementing the module would be impossible - keep answering.
 +
 
 +
== Alternatives for Function Plotting ==
 +
 
 +
* in [[MetaPost]]
 +
** [[source:m-graph.tex|m-graph]] Module (see [http://cm.bell-labs.com/who/hobby/cstr_164.pdf Drawing Graphs with MetaPost] by John D. Hobby)
 +
** functions in [[MetaFun]], see [[manual:metafun-s.pdf|metafun-s.pdf]], section 9.3
 +
* others
 +
** [http://pyx.sourceforge.net/ PyX] - graph drawing through python interface with TeX typesetting & PostScript capabilities
 +
** [http://theory.kitp.ucsb.edu/~paxton/tioga.html Tioga] - creating figures and plots using Ruby, PDF, and TeX
 +
** [http://comp.uark.edu/~luecking/tex/mfpic.html mfpic] - a scheme for producing pictures from LaTeX commands. The LaTeX commands generate a input file to be processed by Metapost.
 +
** [http://matplotlib.sourceforge.net matplotlib] - a Matlab-inspired Python based plotting tool which incorporates many features, including the use of TeX in labels, titles etc.
 +
** [http://tug.ctan.org/tex-archive/graphics/pgf/contrib/pgfplots/ pgfplots] - a TikZ-based LaTeX package for drawing graphs
 +
 
 +
=== Other links ===
 +
* [http://tug.ctan.org/tex-archive/macros/latex/contrib/exceltex/ exceltex] - an interesting LaTeX package to get data from Excel into LaTeX
 +
* [http://peter.affenbande.org/gnuplot/ Lua-based TikZ terminal] - might be interesting to adapt it for ConTeXt (an [http://www.guit.sssup.it/phpbb/viewtopic.php?p=19929 interesting example])
 +
 
 +
 
 +
[[Image:Slo Ministry of Higher Education Science and Technology.jpg]]
 +
 
 +
[[Category:Modules]]
 +
[[Category:Graphics]]
 +
[[Category:Math]]

Revision as of 21:17, 9 November 2010

< Modules | Graphics | Math >

http://www.gnuplot.info/figs/title2.png

Gnuplot is a portable command-line driven utility for function plotting for many platforms.

To make the examples on this page work, you need a modified binary of Gnuplot (see below).

Minimal Example

\usemodule[gnuplot]

% write a script for gnuplot
\startGNUPLOTscript[sin]
   plot sin(x)
\stopGNUPLOTscript

% include the resulting graphic into the document
\useGNUPLOTgraphic[sin]

Calling gnuplot to create the graphic and postprocessing should happen automatically.

Requirements

  • Gnuplot module
    • in TeX Live you need to have context-gnuplot installed, in ConTeXt Minimals you can install it with --extras=t-gnuplot switch
  • Gnuplot has to be installed (and in your PATH)
On most Linux installations this is probably already the case. On Windows you have to create a file gnuplot.bat with something like:
"C:\Program Files\gnuplot\bin\wgnupl32.exe" %*
and put that file to a "visible place" (has to be found in PATH).

To use the ConTeXt terminal (recommended)

Windows

You can take these binaries from Modules in the garden (Note: the binary is old, but I don't have windows any more to compile the latest binary; I can only hope that it still works.)

Unix or Mac

The easiest way to fetch and compile the binary is:

git clone git://github.com/mojca/gnuplot.git
./prepare
./configure
make
(Alternatively you could download gnuplot source from http://www.gnuplot.info, copy context.trm to term/, add #include "context.trm" to src/term.h and follow the same steps for compilation.)

Then replace the old gnuplot executable (once backup-ed) with the one in src/gnuplot or type:

make install

Feel free to contact Mojca in case of problems.

Creating stand-alone, whole-page plots

Here's an example of how to make a stand-alone ConTeXt document with one plot per page:

set term context standalone size 15cm,10cm header '\usetypescript[iwona][ec]' font 'iwona,ss' 10dd
set output 'example.tex'
plot ...

More complex example

(I need to change this example to highlight other aspects. Metapost is kind-of-obsolete since ConTeXt terminal was derived from it and produces superior results. But the example below should still be valid.)

\usemodule[gnuplot]

\setupGNUPLOT[terminal=mp,option=color]

% general settings for the whole document
\startGNUPLOTinclusions

   # you may use TeX commands to format the titles and axes
   set title '\bf Trigonometry'
   set xlabel '$x$'
   set ylabel '$y$'

   # to prevent uneven numbering: will result in
   # (0.0, 0.5, 1.0, 1.5, ...) instead of
   # (0, 0.5, 1, 1.5, ...)
   set format y '\%.1f'
\stopGNUPLOTinclusions

\startGNUPLOTscript[tan]
   plot tan(x) t '$\tan(x)$'
\stopGNUPLOTscript

\startGNUPLOTscript[sin]
   plot 4*sin(x)+x t '$4\sin(x)+x$', x t '$x$' lt 3
\stopGNUPLOTscript

\useGNUPLOTgraphic[tan]
\useGNUPLOTgraphic[sin][width=10cm]

Using other terminals

(Needs a revision.)

Gnuplot support output in different formats with, for example

set terminal mp color solid

will output a metapost document with colors and without dashed lines. After some appropriate preprocessing (with MPtoPDF for this particular case) this file can be included in PDF documents.

You can specify the terminal with

\setupGNUPLOT[terminal=mp,options=color solid]
  • terminal= is mandatory since that't the only way to tell ConTeXt how to preprocess the file.
  • options= is optional and is appended to the end of set terminal [terminal name]. You can also override it by saying
\startGNUPLOTinclusions
set terminal mp color solid
\stopGNUPLOTinclusions

But you have to be careful that you don't set any other terminal with output= then.


Currently supported terminals are:

  • mp/metapost: uses MPtoPDF to convert images to pdf, but the context terminal should replace it
  • ps/postscript: most advanced in the number of supported features
  • png: outputs bitmap images (no preprocessing needed)
  • pdf: outputs PDF directly (no preprocessing needed), but is usually not available in most binaries of gnuplot
  • context:

Development

History

I (Mojca Miklavec) probably mentioned long time ago that I would like to have (or write?) support for Gnuplot inside ConTeXt, but I had no knowledge to do that. Peter Münster posted the very first module for gnuplut support on the mailing list [1], but that version only worked with bash. In the days to follow Hans Hagen has written a new module (based on my numerous "possible and impossible" requests) and Taco additionally provided some bugfixes and minor changes.

The module provides an option to select the most appropriate/suitable driver according to the user's choice (metapost, png, pdf, postscript were the firs ones to be supported). Hans was wondering why there was no context terminal. I took over it's development, the code is almost finished by now, but I guess that Hans now regrets that question already.

He had to invest quite some time into fixing buggy inclusion of text into graphics using textext (if nothing else, he had to read and reply to all the mails [complaints] that me and Taco sent him), just to lead to the conclusion that textext was useless for graphics produced by Gnuplot: too slow and TeX ran out of memory after 10 minutes while processing approximately the 13th plot. After that the new marvellous \sometxt command was born.

I'm currently sticking tiny pieces together in the way I want the module to work. Hans could probably finish the same work that costs me a few days in a few minutes, but after dropping me a bone, he decided to leave me the joy of diving into ConTeXt internals and to let me figure out how to program in ConTeXt by myself. So I still keep spamming the mailing list with numerous questions and both Taco and Hans - without whom implementing the module would be impossible - keep answering.

Alternatives for Function Plotting

  • in MetaPost
  • others
    • PyX - graph drawing through python interface with TeX typesetting & PostScript capabilities
    • Tioga - creating figures and plots using Ruby, PDF, and TeX
    • mfpic - a scheme for producing pictures from LaTeX commands. The LaTeX commands generate a input file to be processed by Metapost.
    • matplotlib - a Matlab-inspired Python based plotting tool which incorporates many features, including the use of TeX in labels, titles etc.
    • pgfplots - a TikZ-based LaTeX package for drawing graphs

Other links


Slo Ministry of Higher Education Science and Technology.jpg