Changes

Jump to navigation Jump to search
3,402 bytes added ,  23:58, 13 July 2020
lmtx example for gnuplot inclusion
< [[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.6.tex|m0 or later (or self-gnuplotcompiled binary).tex]]: the source file
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 ==
'''Development'''<texcode>\usemodule[gnuplot]
* % write a script for gnuplot\startGNUPLOTscript[http://renojrl.lrv.uvsq.fr/projects/gpcontext/ darcs repositorysin] plot sin(maintained by Renaud Aubinx)* [http://groups.google.com/group/gnuplot-context mailing list]\stopGNUPLOTscript
== Terminals ==% include the resulting graphic into the document\useGNUPLOTgraphic[sin]</texcode>
Gnuplot support output in different formats with, for example set terminal mp color solidwill output a metapost document with colors Calling gnuplot to create the graphic and without dashed lines. After some appropriate preprocessing (with [[MPtoDF]] for this particular case) this file can be included in PDF documentspostprocessing should happen automatically.
You can specify the terminal with<texcode>\setupGNUPLOT[output=mp,options=color solid]</texcode>Requirements ==
* '''[http://modules.contextgarden.net/gnuplot Gnuplot module]'''** in TeX Live you need to have <code>output=context-gnuplot</code> is mandatory since that't the only way to tell installed, in [[ConTeXt how to preprocess the file.* Standalone]] you can install it with <code>options--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 optional usually also shipped and you need to make sure that it is appended to in PATH. In case that the end of binary has a different name, you could create a file <code>set terminal [terminal name]gnuplot.bat</code>with something like: "C:\Program Files\gnuplot\bin\wgnupl32. You can also override it by sayingexe" %*:(if that was the binary name) and put that file to a <texcodei>\startGNUPLOTinclusionsset terminal mp color solid\stopGNUPLOTinclusions"visible place"</texcodei>But you have (has to be careful that you don't set any other terminal with found in PATH). Please note: if calling <code>output=gnuplot</code> thenfrom cmd works for you, there is no need to do anything extra.* '''[[Write18]]''' has to be enabled=== To use the ConTeXt terminal (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.
<!-- Another way to specify it is If you want to override use the terminal setting version from trunk: # unofficial; you can also use official cvs git clone git://github.com/gnuplot/gnuplot.git ./prepare ./configure make make installI use <code>./configure --prefix=$PWD/inst</code>to avoid cluttering the system and install gnuplot to my personal directory. You can use other flags to configure for a different choice of GUI terminals.
Currently supported terminals are:* If you want to use the released version, get it from [http://wwwsourceforge.gnuplot.infonet/docsprojects/gnuplot.html#mp mp/metapost]: <b>most beautiful results</b>, uses [[MPtoPDF]] to convert images to pdf* [http://www.gnuplot.info/docsfiles/gnuplot.html#postscript_ ps/postscriptsourceforge]: uses newpstopdf to convert images to pdf; ''currently some problems with rotated images unless and do the same, just skip the <code>option=eps./prepare</code> is used''* [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
Multiple plots (more imagesThe latest version of context terminal is available at http:/pages of output) are not supported (there's probably no reason to) since you can split the graphs in subsequent <code>\startGNUPLOTgraphic /github.com/mojca/gnuplot/raw/master/term/context.. \stopGNUPLOTgraphic if necessary</code>trm.
=== Minimal Example ===Feel free to contact [[User:Mojca Miklavec|Mojca]] in case of problems.
<texcode>\usemodule[gnuplot]== Creating stand-alone, whole-page plots ==
% creating the graphics\startGNUPLOTgraphics{sin} Here's an example of how to make a stand-alone ConTeXt document with one plot sin(x)\stopGNUPLOTgraphicsper page:
% including the graphics into the document set term context standalone size 15cm,10cm header '\useGNUPLOTgraphicusetypescript[siniwona]' font 'iwona,ss' 10dd</texcode> set output 'example.tex'=== More complex example with MetaPost === 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 == Example with <code>set terminal mp {fontname}</code> a bit (http://www.gnuplot.info/docs/gnuplot.html#mp).externalfigure ==
=== More complex exampleIn [[LMTX]] we can use externalfigure for gnuplot files like this: Multiple terminals ===
You can use different terminals for plotting the same functionm-gnuplot-demo.gp<texcode>set format xy "$%g$"
{{todo|an example, similar to the one in [[source:m-gnuplot.tex|m-gnuplot.tex]], some images to get set title 'This is a visual impression plot of $y=\\sin(x)$'set xlabel 'This is the $x$ axis'set ylabel 'This is the main differences in terminals}}$y$ axis'
plot [0:6.28] [0:1] sin(x)</texcode> Then including it in the .tex file with externalfigure and svg conversion: <texcode>\usemodule[gnuplot] \starttext\externalfigure[m-gnuplot-demo.gp][conversion=svg,width= Requirements 4cm]\stoptext</texcode> ==Using other terminals == <i>(Needs a revision.)</i> Gnuplot support output in different formats with, for example 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. 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>\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]]
174

edits

Navigation menu