Changes

Jump to navigation Jump to search
987 bytes added ,  23:58, 13 July 2020
lmtx example for gnuplot inclusion
[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 4.6.0 or later (see belowor self-compiled binary).
== Minimal Example ==
* '''[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>--extrasmodules=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 have need to 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 do anything extra.* '''[[write18Write18]]''' has to be enabled
=== To use the ConTeXt terminal (recommended) ===
==== Windows ====
You can take fetch binaries from [http://dl.contextgardensourceforge.net/modulesprojects/gnuplot-win.zip these/files/gnuplot/ sourceforge (released versions)] binaries or from [[moduleshttp://www.tatsuromatsuoka.com/gnuplot-win|Modules in the garden]] ''/Eng/winbin/ Tatsuro Matsuoka (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 workscvs 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 fetch and compile your own. If you want to use the binary isversion from trunk: # unofficial; you can also use official cvs git clone git://github.com/mojcagnuplot/gnuplot.git
./prepare
./configure
make
:''(Alternatively you could download gnuplot source from http: make installI use <code>./configure --prefix=$PWD/inst</wwwcode> to avoid cluttering the system and install gnuplot to my personal directory.gnuplotYou can use other flags to configure for a different choice of GUI terminals.info If you want to use the released version, copy get it from [http://githubsourceforge.comnet/mojcaprojects/gnuplot/rawfiles/mastergnuplot/term/context.trm context.trmsourceforge] to and do the same, just skip the <code>term./prepare</code>, add <code>#include ". The latest version of contextterminal is available at http://github.trm"<com/mojca/gnuplot/raw/code> to <code>srcmaster/term/context.h</code> and follow the same steps for compilationtrm.)''
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.
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=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 y '\%.1f'
\stopGNUPLOTinclusions
\useGNUPLOTgraphic[tan]
\useGNUPLOTgraphic[sin][width=10cm]
</texcode>
 
== Example with externalfigure ==
 
In [[LMTX]] we can use externalfigure for gnuplot files like this:
 
m-gnuplot-demo.gp
<texcode>
set format xy "$%g$"
 
set title 'This is a plot of $y=\\sin(x)$'
set xlabel 'This is the $x$ axis'
set ylabel 'This is the $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=4cm]
\stoptext
</texcode>
<!-- 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/docsdocs_4.0/gnuplot.html#png_%28NEW%29 png (OLD1) ],[http://www.gnuplot.info/docs_4.2/gnuplot.html#x1-41500051.53 png(2)]: outputs bitmap images (no preprocessing needed)* [http://www.gnuplot.info/docsdocs_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''':
== Development == * The current gnuplot-documentation can be downloaded [http://groupswww.googlegnuplot.cominfo/groupdocs_4.6/gnuplot-context mailing list.pdf here].
== History ==
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.
 
== Old wiki pages ==
* 2006 - [[Gnuplot Development]]
 
== 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
=== 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:MathSciences]]
174

edits

Navigation menu