Gnuplot.jl/v1.3.0/style/index.html
Giorgio Calderone 7d3d0321d0 Updated
2020-04-28 19:20:13 +02:00

19 lines
11 KiB
HTML

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Style guide · 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="../options/">Package options</a></li><li class="is-active"><a class="tocitem" href>Style guide</a></li><li><a class="tocitem" href="../terminals/">Gnuplot terminals</a></li><li><a class="tocitem" href="../recipes/">Plot recipes</a></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>Style guide</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Style guide</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://github.com/gcalderone/Gnuplot.jl/blob/master/docs/src/style.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="Style-Guide-1"><a class="docs-heading-anchor" href="#Style-Guide-1">Style Guide</a><a class="docs-heading-anchor-permalink" href="#Style-Guide-1" title="Permalink"></a></h1><p>The <strong>Gnuplot.jl</strong> loose syntax allows to create a plot using very different approaches. While this was one of the initial purposes for the package, it may lead to decreased code readability if not used judiciously.</p><p>Here I will summarize a few, non-mandatory, guidelines which allows to maintain a neat syntax and a high readability:</p><h3 id="Use-macros-without-parentheses-and-commas:-1"><a class="docs-heading-anchor" href="#Use-macros-without-parentheses-and-commas:-1">1 - Use macros without parentheses and commas:</a><a class="docs-heading-anchor-permalink" href="#Use-macros-without-parentheses-and-commas:-1" title="Permalink"></a></h3><p>The two most important symbols exported by the package (<code>@gp</code> and <code>@gsp</code>) are macros. As such they are supposed to be invoked without parentheses and commas. E.g. use:</p><pre><code class="language-julia">@gp x y &quot;with lines&quot;</code></pre><p>in place of</p><pre><code class="language-julia">@gp(x, y, &quot;with lines&quot;)</code></pre><p>If you have very long lines you may split them in multiple statements using the <code>:-</code> symbol, which resembles both hyphenation in natural language and indentation for the plot-producing code:</p><pre><code class="language-julia">@gp &quot;set grid&quot; :-
@gp :- x y &quot;with lines&quot;</code></pre><p>Note that the trailing <code>:-</code> symbol is not mandatory. If omitted, the plot will be updated at each statement (rather than at the last one).</p><h3 id="Use-keywords-in-place-of-gnuplot-commands:-1"><a class="docs-heading-anchor" href="#Use-keywords-in-place-of-gnuplot-commands:-1">2 - Use keywords in place of gnuplot commands:</a><a class="docs-heading-anchor-permalink" href="#Use-keywords-in-place-of-gnuplot-commands:-1" title="Permalink"></a></h3><p>As discussed in <a href="../basic/#Keywords-for-common-commands-1">Keywords for common commands</a> several commonly used gnuplot commands can be replaced with a keyword. E.g. you can use</p><pre><code class="language-julia">@gp ... xrange=[-1,5] ...</code></pre><p>in place of</p><pre><code class="language-julia">@gp ... &quot;set xrange [-1:5]&quot; ...</code></pre><p>This help reducing the number of strings, as well as the associated interpolating characters (<code>$</code>), and results in a more concise syntax.</p><h3 id="Use-abbreviations-for-commands-and-keywords:-1"><a class="docs-heading-anchor" href="#Use-abbreviations-for-commands-and-keywords:-1">3 - Use abbreviations for commands and keywords:</a><a class="docs-heading-anchor-permalink" href="#Use-abbreviations-for-commands-and-keywords:-1" title="Permalink"></a></h3><p>Many gnuplot commands, as well as all keywords (see <a href="../basic/#Keywords-for-common-commands-1">Keywords for common commands</a>), can be abbreviated as long as the abbreviation is unambiguous. E.g., the following code:</p><pre><code class="language-julia">@gp &quot;set grid&quot; &quot;set key left&quot; &quot;set logscale y&quot;
@gp :- &quot;set title &#39;Plot title&#39;&quot; &quot;set label &#39;X label&#39;&quot; &quot;set xrange [0:*]&quot;
@gp :- x y &quot;with lines&quot;</code></pre><p>can be replaced with a shorter version:</p><pre><code class="language-julia">@gp &quot;set grid&quot; k=&quot;left&quot; ylog=true
@gp :- tit=&quot;Plot title&quot; xlab=&quot;X label&quot; xr=[0,NaN]
@gp :- x y &quot;w l&quot;</code></pre><p>Besides being more idiomatic, the possibility to exploit abbreviations is of great importance when performing interactive data exploration.</p><p>Moreover, in many gnuplot examples and documentation it is very common to use abbreviations (i.e. <code>w l</code> in place of <code>with lines</code>) so there is no reason to avoid them in <strong>Gnuplot.jl</strong>.</p><h3 id="If-possible,-follow-the-*commands*-*data*-*plot-specs*-order-1"><a class="docs-heading-anchor" href="#If-possible,-follow-the-*commands*-*data*-*plot-specs*-order-1">4 - If possible, follow the <em>commands</em> -&gt; <em>data</em> + <em>plot specs</em> order</a><a class="docs-heading-anchor-permalink" href="#If-possible,-follow-the-*commands*-*data*-*plot-specs*-order-1" title="Permalink"></a></h3><p>The two following examples produce exactly the same plot:</p><pre><code class="language-julia">x = -10.:10
@gp &quot;set grid&quot; &quot;set multiplot layout 2,1&quot;
@gp :- 1 x x.^2 &quot;w l t &#39;f(x) = x^2&quot; # first plot
@gp :- 2 x x.^3 &quot;w l t &#39;f(x) = x^3&quot; # second plot</code></pre><p>and</p><pre><code class="language-julia">@gp 2 x x.^3 &quot;w l t &#39;f(x) = x^3&quot; # second plot
@gp :- 1 x x.^2 &quot;w l t &#39;f(x) = x^2&quot; # first plot
@gp :- &quot;set grid&quot; &quot;set multiplot layout 2,1&quot;</code></pre><p>However, the first form appears more <em>logical</em> and easy to follow.</p><p>In analogy with previous example, even on single plot, the following form</p><pre><code class="language-julia">@gp &quot;set grid&quot;
@gp :- x x.^2 &quot;w l t &#39;f(x) = x^2&quot;</code></pre><p>should be preferred over</p><pre><code class="language-julia">@gp x x.^2 &quot;w l t &#39;f(x) = x^2&quot;
@gp :- &quot;set grid&quot;</code></pre><p>even if the output is exactly the same.</p><h3 id="Join-multiple-command-strings:-1"><a class="docs-heading-anchor" href="#Join-multiple-command-strings:-1">5 - Join multiple command strings:</a><a class="docs-heading-anchor-permalink" href="#Join-multiple-command-strings:-1" title="Permalink"></a></h3><p>Instead of specifying several commands as strings</p><pre><code class="language-julia">@gp :- &quot;set key off&quot; &quot;set auto fix&quot; &quot;set size square&quot;
@gp :- &quot;set offsets graph .05, graph .05, graph .05, graph .05&quot;
@gp :- &quot;set border lw 1 lc rgb &#39;white&#39;&quot;</code></pre><p>join them in a single string using triple quotes and <code>;</code></p><pre><code class="language-julia">@gp :- &quot;&quot;&quot;set key off; set auto fix; set size square;
set offsets graph .05, graph .05, graph .05, graph .05;
set border lw 1 lc rgb &#39;white&#39;; &quot;&quot;&quot;</code></pre></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../options/">« Package options</a><a class="docs-footer-nextpage" href="../terminals/">Gnuplot terminals »</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="Tuesday 28 April 2020 19:19">Tuesday 28 April 2020</span>. Using Julia version 1.4.0.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>