Gnuplot.jl/dev/terminals/index.html
Giorgio Calderone 27f73203be Docs updated
2020-04-08 00:12:07 +02:00

28 lines
12 KiB
HTML

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Gnuplot terminals · Gnuplot.jl</title><link href="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-dark.css" data-theme-name="documenter-dark"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><a class="docs-logo" href="../"><img src="../assets/logo.png" alt="Gnuplot.jl logo"/></a><div class="docs-package-name"><span class="docs-autofit">Gnuplot.jl</span></div><form class="docs-search" action="../search/"><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li><a class="tocitem" href="../">Home</a></li><li><a class="tocitem" href="../install/">Installation</a></li><li><a class="tocitem" href="../basic/">Basic usage</a></li><li><a class="tocitem" href="../advanced/">Advanced usage</a></li><li><a class="tocitem" href="../style/">Style guide</a></li><li class="is-active"><a class="tocitem" href>Gnuplot terminals</a><ul class="internal"><li><a class="tocitem" href="#Interactive-terminals-(wxt-and-qt)-1"><span>Interactive terminals (<code>wxt</code> and <code>qt</code>)</span></a></li><li><a class="tocitem" href="#Plot-in-a-terminal-application-(dumb,-sixel-and-sixelgd)-1"><span>Plot in a terminal application (<code>dumb</code>, <code>sixel</code> and <code>sixelgd</code>)</span></a></li><li><a class="tocitem" href="#Export-to-image-files-1"><span>Export to image files</span></a></li><li><a class="tocitem" href="#The-cairolatex-terminal-1"><span>The <code>cairolatex</code> terminal</span></a></li></ul></li><li><a class="tocitem" href="../examples/">Examples</a></li><li><a class="tocitem" href="../api/">API</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href>Gnuplot terminals</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Gnuplot terminals</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://github.com/gcalderone/Gnuplot.jl/blob/master/docs/src/terminals.md" title="Edit on GitHub"><span class="docs-icon fab"></span><span class="docs-label is-hidden-touch">Edit on GitHub</span></a><a class="docs-settings-button fas fa-cog" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-sidebar-button fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article class="content" id="documenter-page"><h1 id="Gnuplot-terminals-1"><a class="docs-heading-anchor" href="#Gnuplot-terminals-1">Gnuplot terminals</a><a class="docs-heading-anchor-permalink" href="#Gnuplot-terminals-1" title="Permalink"></a></h1><p>Gnuplot provides dozens of terminals to display plots or export them into files (see <a href="../api/#Gnuplot.terminals"><code>terminals()</code></a> to get a list of enabled terminals on your platform). This section discuss a few tips on how to use the most common terminals.</p><p>To use a specific terminal for interactive use you may either add it as initialization command for all new session with (see <a href="../advanced/#Options-1">Options</a>):</p><pre><code class="language-julia">push!(Gnuplot.options.init, &quot;set term wxt&quot;)</code></pre><p>or directly send the command to a specific session (see <a href="../advanced/#Direct-command-execution-1">Direct command execution</a>)</p><pre><code class="language-julia">gpexec(&quot;set term wxt&quot;)</code></pre><p>See official <a href="http://gnuplot.sourceforge.net/documentation.html">gnuplot documentation</a> for further info on terminals and their options.</p><h2 id="Interactive-terminals-(wxt-and-qt)-1"><a class="docs-heading-anchor" href="#Interactive-terminals-(wxt-and-qt)-1">Interactive terminals (<code>wxt</code> and <code>qt</code>)</a><a class="docs-heading-anchor-permalink" href="#Interactive-terminals-(wxt-and-qt)-1" title="Permalink"></a></h2><p>The multiplatform <code>wxt</code> and <code>qt</code> terminals are among the most widely used ones for their nicely looking outputs on display and for their interactive capabilities.</p><p>You may set them as terminal with:</p><pre><code class="language-none">&quot;set term wxt size 800,600&quot;</code></pre><p>or</p><pre><code class="language-none">&quot;set term qt size 800,600&quot;</code></pre><p>(the <code>size 800,600</code> is optional and can be omitted).</p><p>Press the <code>h</code> key on the window to display an help message with all available keyboard shortcuts. In particular press <code>6</code> to enable printing plot coordinates on Julia stdout (ensure mouse is enabled with <code>m</code>).</p><h2 id="Plot-in-a-terminal-application-(dumb,-sixel-and-sixelgd)-1"><a class="docs-heading-anchor" href="#Plot-in-a-terminal-application-(dumb,-sixel-and-sixelgd)-1">Plot in a terminal application (<code>dumb</code>, <code>sixel</code> and <code>sixelgd</code>)</a><a class="docs-heading-anchor-permalink" href="#Plot-in-a-terminal-application-(dumb,-sixel-and-sixelgd)-1" title="Permalink"></a></h2><p>Gnuplot supports plotting in a terminal application, with no need for X11 or other GUI support, via the <code>dumb</code>, <code>sixel</code> and <code>sixelgd</code> terminals. These are extremely useful when you run Julia on a remote shell through <code>ssh</code>, with no X11 forwarding. You may set these terminals with one of the following command:</p><pre><code class="language-none">&quot;set term dumb&quot;
&quot;set term sixel&quot;
&quot;set term sixelgd&quot;</code></pre><p>The <code>dumb</code> terminal uses ASCII characters to draw a plot, while <code>sixel</code> and <code>sixelgd</code> actually use bitmaps (but require Sixel support to be enabled in the terminal, e.g. <code>xterm -ti vt340</code>). A sixel plot on <code>xterm</code> looks as follows: <img src="../assets/sixelgd.png" alt/></p><p>The above terminals are available if gnuplot has been compiled with the <code>--with-bitmap-terminals</code> option enabled and Libgd (only for <code>sixelgd</code>).</p><h2 id="Export-to-image-files-1"><a class="docs-heading-anchor" href="#Export-to-image-files-1">Export to image files</a><a class="docs-heading-anchor-permalink" href="#Export-to-image-files-1" title="Permalink"></a></h2><p>Gnuplot provides dozens of terminals able to export on files. Examples are:</p><ul><li><code>cairopng</code> to export PNG files;</li><li><code>pdfcairo</code> for PDF;</li><li><code>jpeg</code> for JPG;</li><li><code>gif</code> for GIF (see <a href="../advanced/#Animations-1">Animations</a>).</li></ul><p>All the above terminals support the <code>size</code> and <code>fontscale</code> options to quickly adjust the size of the rasterized image and the size of the font respectively. E.g.:</p><pre><code class="language-julia">save(term=&quot;pngcairo size 480,360 fontscale 0.8&quot;, output=&quot;output.png&quot;)</code></pre><p>(see also <a href="../api/#Gnuplot.save"><code>save()</code></a>).</p><p>Gnuplot is also able to export vector (i.e. non-raster) plots through the <code>svg</code> terminal.</p><h2 id="The-cairolatex-terminal-1"><a class="docs-heading-anchor" href="#The-cairolatex-terminal-1">The <code>cairolatex</code> terminal</a><a class="docs-heading-anchor-permalink" href="#The-cairolatex-terminal-1" title="Permalink"></a></h2><p>The <code>cairolatex</code> terminal allows to produce high quality plots by splitting the output into a PDF file (containing a rasterized image of a plot) and a <code>.tex</code> file (containing all the text as <span>$\LaTeX$</span> code). The following example shows how to write plot tics and an equation in <span>$\LaTeX$</span>:</p><pre><code class="language-julia">x = LinRange(-2pi, 2pi, 1000)
@gp t=&quot;Polynomial approximation of sin(x)&quot; &quot;set style fill transparent solid 0.6 noborder&quot;
@gp :- raw&quot;&quot;&quot;set xtics (&#39;$-\pi$&#39; -pi, &#39;$-\pi/2$&#39; -pi/2, 0, &#39;$\pi/2$&#39; pi/2, &#39;$\pi$&#39; pi)&quot;&quot;&quot;
@gp :- xr=3.8.*[-1, 1] yr=[-1.5,1.5] key=&quot;box opaque left horiz&quot; linetypes(:Blues_3) &quot;set grid front&quot;
latex = raw&quot;&quot;&quot;\begin{minipage}[c]{\textwidth}\begin{equation*}&quot;&quot;&quot; *
raw&quot;&quot;&quot;\sin(x) = \sum_0^{+\infty} \frac{(-1)^n}{(2n + 1)!} x^{2n+1}&quot;&quot;&quot; *
raw&quot;&quot;&quot;\end{equation*} \end{minipage}&quot;&quot;&quot;
@gp :- &quot;set label at graph 0.62,0.2 front center &#39;$latex&#39;&quot;
approx = fill(0., length(x));
@gp :- x sin.(x) approx .+= x &quot;w filledcurve t &#39;n=0&#39; lt 1&quot;
@gp :- x sin.(x) approx .+= -x.^3/6 &quot;w filledcurve t &#39;n=1&#39; lt 2&quot;
@gp :- x sin.(x) approx .+= x.^5/120 &quot;w filledcurve t &#39;n=2&#39; lt 3&quot;
@gp :- x sin.(x) approx .+= -x.^7/5040 &quot;w filledcurve t &#39;n=3&#39; lt 4&quot;
@gp :- x sin.(x) &quot;w l t &#39;sin(x)&#39; lw 2 lc rgb &#39;black&#39;&quot;
save(term=&quot;cairolatex pdf input color dashed size 5in,3.3in&quot;, output=&quot;test.tex&quot;)</code></pre><div class="admonition is-warning"><header class="admonition-header">Warning</header><div class="admonition-body"><p>If you add a path in the <code>output=</code> keyword this will also be copied in the the <code>.tex</code> file. I suggest to use just filenames, with no path, in order to avoid possible errors when compiling <span>$\LaTeX$</span> code.</p></div></div><p>The two output files (<code>test.tex</code> and <code>test.pdf</code>) can then be included in a <span>$\LaTeX$</span> file as follows:</p><pre><code class="language-latex">\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{color}
\begin{document}
\begin{figure}
\input{test.tex}
\end{figure}
\end{document}</code></pre><p>And the output is: <img src="../assets/cairolatex.png" alt/></p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../style/">« Style guide</a><a class="docs-footer-nextpage" href="../examples/">Examples »</a></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> on <span class="colophon-date" title="Wednesday 8 April 2020 00:09">Wednesday 8 April 2020</span>. Using Julia version 1.4.0.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>