Changes

Jump to navigation Jump to search
3,090 bytes added ,  19:24, 8 June 2020
m
no edit summary
< [[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.
[[source:m-gnuplotTo make the examples on this page work, you need Gnuplot 4.tex|m-gnuplot6.tex]]: the source file ''0 or later (contextgarden is not updated to the latest version yet, so you may not be able to see thisor self-compiled binary)''.
After Peter Münster posted the first module for gnuplut support on the mailing list [http://article.gmane.org/gmane.comp.tex.context/24884] (which only works with bash), Hans Hagen (see [http://article.gmane.org/gmane.comp.tex.context/24935] [http://article.gmane.org/gmane.comp.tex.context/24965]) wrote another one and Taco additionally provided some bugfixes and minor changes. The module is now a part of the official distribution, but may undergo some other minor changes in the short term (use with care for some time).== Minimal Example ==
== Terminals ==<texcode>\usemodule[gnuplot]
Gnuplot support output in different formats with, % write a script for examplegnuplot set terminal mp color solid\startGNUPLOTscript[sin]will output a metapost document with colors and without dashed lines. After some appropriate preprocessing plot sin(with [[MPtoDF]] for this particular casex) this file can be included in PDF documents.\stopGNUPLOTscript
You can specify % include the terminal with<texcode>resulting graphic into the document\setupGNUPLOTuseGNUPLOTgraphic[output=mp,options=color solidsin]
</texcode>
* <code>output=</code> is mandatory since that't the only way Calling gnuplot to tell ConTeXt how to preprocess create the file.* <code>options=</code> is optional graphic and is appended to the end of <code>set terminal [terminal name]</code>postprocessing should happen automatically. You can also override it by saying<texcode>\startGNUPLOTinclusionsset 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.= Requirements ==
* '''[http://modules.contextgarden.net/gnuplot Gnuplot module]'''** in TeX Live you need to have <!code>context-gnuplot</code> installed, in [[ConTeXt Standalone]] you can install it with <code>- Another way -modules=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 gnuplot.exe is usually also shipped and you need to specify make sure that it is in PATH. In case that the binary has a different name, you could create a file <code>gnuplot.bat</code> with something like: "C:\Program Files\gnuplot\bin\wgnupl32.exe" %*:(if that was the binary name) and put that file to a <i>"visible place"</i> (has to be found in PATH). Please note: if calling <code>gnuplot</code> from cmd works for you, there is no need to override do anything extra.* '''[[Write18]]''' has to be enabled=== To use the ConTeXt terminal setting (recommended) ======= Windows ====You can fetch binaries from [http://sourceforge.net/projects/gnuplot/files/gnuplot/ sourceforge (released versions)] or from [http://www.tatsuromatsuoka.com/gnuplot/Eng/winbin/ Tatsuro Matsuoka (latest cvs version)].==== -->Unix or Mac ====The easiest way is to use version 4.6.0 or later shipped by your distribution. If that version is too old, you need to compile your own.
Currently supported terminals areIf you want to use the version from trunk:* [http # unofficial; you can also use official cvs git clone git://wwwgithub.com/gnuplot.info/docs/gnuplot.html#mp mp/metapost]: <b>most beautiful results</b>, uses [[MPtoPDF]] to convert images to pdfgit* [http://www .gnuplot.info/docs/gnuplotprepare .html#postscript_ ps/postscript]: uses newpstopdf to convert images to pdf; ''currently some problems with rotated images unless configure make make installI use <code>option./configure --prefix=eps$PWD/inst</code> is used''* [http://www.to avoid cluttering the system and install gnuplotto my personal directory.info/docs/gnuplotYou can use other flags to configure for a different choice of GUI terminals.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
Multiple plots (more imagesIf you want to use the released version, get it from [http://sourceforge.net/projects/gnuplot/files/gnuplot/pages of output) are not supported (there's probably no reason to) since you can split sourceforge] and do the same, just skip the graphs in subsequent <code>\startGNUPLOTgraphic ... \stopGNUPLOTgraphic if necessary/prepare</code>.
=== Minimal Example ===The latest version of context terminal is available at http://github.com/mojca/gnuplot/raw/master/term/context.trm.
<texcode>\usemoduleFeel free to contact [gnuplot[User:Mojca Miklavec|Mojca]]in case of problems.
% creating the graphics\startGNUPLOTgraphics{sin} plot sin(x)\stopGNUPLOTgraphics== Creating stand-alone, whole-page plots ==
% including the graphics into the Here's an example of how to make a stand-alone ConTeXt document\useGNUPLOTgraphic[sin]</texcode>with one plot per page:
=== More complex set term context standalone size 15cm,10cm header '\usetypescript[iwona]' font 'iwona,ss' 10dd set output 'example with MetaPost ===.tex' plot ...
Metapost produces the plots of a relatively high quality. You can use TeX commands to format the title, label axes and legend.== More complex example ==
<texcode>
\usemodule[gnuplot]
% output may be "mp/metapost", "ps/postscript", "pdf" or "png"; ps is currently the default\setupGNUPLOT[outputterminal=mptikz,option=color]% terminal=mp if you only have an old gnuplot at hand
% general settings for the whole document
# (0.0, 0.5, 1.0, 1.5, ...) instead of
# (0, 0.5, 1, 1.5, ...)
set format yaxis y '\%.1f'
\stopGNUPLOTinclusions
\startGNUPLOTgraphics{startGNUPLOTscript[tan}]
plot tan(x) t '$\tan(x)$'
\stopGNUPLOTgraphicsstopGNUPLOTscript
\startGNUPLOTgraphics{startGNUPLOTscript[sin}]
plot 4*sin(x)+x t '$4\sin(x)+x$', x t '$x$' lt 3
\stopGNUPLOTgraphicsstopGNUPLOTscript
\useGNUPLOTgraphic[tan]
</texcode>
There's only one problem that you have to be careful about: [[MetaPost]] terminal uses <code>cmr</code> fonts for labels. If you have the stand-alone distributions, you either have to install them by yourself or to play with <code>set terminal mp {fontname}</code> a bit (http://www.gnuplot.info/docs/gnuplot.html#mp).== Using other terminals ==
=== More complex example: Multiple terminals ===<i>(Needs a revision.)</i>
You can use Gnuplot support output in different terminals formats with, for plotting the same functionexample set terminal mp color solidwill 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.
{{todo|an example, similar to You can specify the one in terminal with<texcode>\setupGNUPLOT[[source:m-gnuplot.tex|m-gnuplot.tex]terminal=mp,options=color solid], some images to get a visual impression of the main differences in terminals}}</texcode>
* <code>terminal=</code> is mandatory since that't the only way to tell ConTeXt how to preprocess the file.* <code>options= Requirements </code> is optional and is appended to the end of <code>set terminal [terminal name]</code>. You can also override it by saying<texcode>\startGNUPLOTinclusionsset 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 (attention: links not from the latest documentation):* [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_4.0/gnuplot.html#png_%28NEW%29 png (1)],[http://www.gnuplot.info/docs_4.2/gnuplot.html#x1-41500051.53 png (2)]: outputs bitmap images (no preprocessing needed)* [http://www.gnuplot.info/docs_4.0/gnuplot.html#pdf pdf (old)],[http://www.gnuplot.info/docs_4.2/gnuplot.html#x1-41300051.51 pdf (new)]: outputs PDF directly for (no preprocessing needed), but is usually not available in most binaries of gnuplot* '''context''': The current gnuplot-documentation can be downloaded [http://www.gnuplot.info/docs_4.6/gnuplot.pdf here]. == 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.
You have I'm currently sticking tiny pieces together in the way I want the module to have Gnuplot installed (and in your PATH)work. On most Linux installations this is Hans could probably already finish the case. On Windows you either need same work that costs me a few days in a few minutes, but after dropping me a bone, he decided to put leave me the gnuplot binary joy of diving into ConTeXt internals and to let me figure out how to program in PATH manually or to create a file <code>pgnuplotConTeXt by myself.bat</code> So I still keep spamming the mailing list with "C:\Program Files\gnuplot\wgnupl32.exe" %1 %2 %3 %4 %5 %6 %7 %8 %9numerous questions and both Taco and put that file to a <i>"visible place"</i> (has to Hans - without whom implementing the module would be found in PATH)impossible - keep answering.
For most terminals you need <b>texmfstart</b>(.exe) as well. In case you don't have it yet, you can grab it == Old wiki pages ==* 2006 - [http://www.pragma-ade.com/context/current/cont-win.zip here[Gnuplot Development]].
[[write18]] has to be enabled as well.
== 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 - MetaPost in ConTeXt|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
 
[[Image:Slo Ministry of Higher Education Science and Technology.jpg]]
[[Category:Modules]]
[[Category:Graphics]]
[[Category:MathSciences]]

Navigation menu