var documenterSearchIndex = {"docs": [{"location":"style/#Style-Guide-1","page":"Style guide","title":"Style Guide","text":"","category":"section"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"The Gnuplot.jl 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.","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"Here I will summarize a few, non-mandatory, guidelines which allows to maintain a neat syntax and a high readability:","category":"page"},{"location":"style/#Use-macros-without-parentheses-and-commas:-1","page":"Style guide","title":"1 - Use macros without parentheses and commas:","text":"","category":"section"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"The two most important symbols exported by the package (@gp and @gsp) are macros. As such they are supposed to be invoked without parentheses and commas. E.g. use:","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"@gp x y \"with lines\"","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"in place of","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"@gp(x, y, \"with lines\")","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"If you have very long lines you may split them in multiple statements using the :- symbol, which resembles both hyphenation in natural language and indentation for the plot-producing code:","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"@gp \"set grid\" :-\n@gp :- x y \"with lines\"","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"Note that the trailing :- symbol is not mandatory. If omitted, the plot will be updated at each statement (rather than at the last one).","category":"page"},{"location":"style/#Use-keywords-in-place-of-gnuplot-commands:-1","page":"Style guide","title":"2 - Use keywords in place of gnuplot commands:","text":"","category":"section"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"As discussed in Keywords for common commands several commonly used gnuplot commands can be replaced with a keyword. E.g. you can use","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"@gp ... xrange=[-1,5] ...","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"in place of","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"@gp ... \"set xrange [-1:5]\" ...","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"This help reducing the number of strings, as well as the associated interpolating characters ($), and results in a more concise syntax.","category":"page"},{"location":"style/#Use-abbreviations-for-commands-and-keywords:-1","page":"Style guide","title":"3 - Use abbreviations for commands and keywords:","text":"","category":"section"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"Many gnuplot commands, as well as all keywords (see Keywords for common commands), can be abbreviated as long as the abbreviation is unambiguous. E.g., the following code:","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"@gp \"set grid\" \"set key left\" \"set logscale y\"\n@gp :- \"set title 'Plot title'\" \"set label 'X label'\" \"set xrange [0:*]\"\n@gp :- x y \"with lines\"","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"can be replaced with a shorter version:","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"@gp \"set grid\" k=\"left\" ylog=true\n@gp :- tit=\"Plot title\" xlab=\"X label\" xr=[0,NaN]\n@gp :- x y \"w l\"","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"Besides being more idiomatic, the possibility to exploit abbreviations is of great importance when performing interactive data exploration.","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"Moreover, in many gnuplot examples and documentation it is very common to use abbreviations (i.e. w l in place of with lines) so there is no reason to avoid them in Gnuplot.jl.","category":"page"},{"location":"style/#If-possible,-follow-the-*commands*-*data*-*plot-specs*-order-1","page":"Style guide","title":"4 - If possible, follow the commands -> data + plot specs order","text":"","category":"section"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"The two following examples produce exactly the same plot:","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"x = -10.:10\n@gp \"set grid\" \"set multiplot layout 2,1\"\n@gp :- 1 x x.^2 \"w l t 'f(x) = x^2\" # first plot\n@gp :- 2 x x.^3 \"w l t 'f(x) = x^3\" # second plot","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"and","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"@gp 2 x x.^3 \"w l t 'f(x) = x^3\" # second plot\n@gp :- 1 x x.^2 \"w l t 'f(x) = x^2\" # first plot\n@gp :- \"set grid\" \"set multiplot layout 2,1\"","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"However, the first form appears more logical and easy to follow.","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"In analogy with previous example, even on single plot, the following form","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"@gp \"set grid\"\n@gp :- x x.^2 \"w l t 'f(x) = x^2\"","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"should be preferred over","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"@gp x x.^2 \"w l t 'f(x) = x^2\"\n@gp :- \"set grid\"","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"even if the output is exactly the same.","category":"page"},{"location":"style/#Join-multiple-command-strings:-1","page":"Style guide","title":"5 - Join multiple command strings:","text":"","category":"section"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"Instead of specifying several commands as strings","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"@gp :- \"set key off\" \"set auto fix\" \"set size square\"\n@gp :- \"set offsets graph .05, graph .05, graph .05, graph .05\"\n@gp :- \"set border lw 1 lc rgb 'white'\"","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"join them in a single string using triple quotes and ;","category":"page"},{"location":"style/#","page":"Style guide","title":"Style guide","text":"@gp :- \"\"\"set key off; set auto fix; set size square;\n set offsets graph .05, graph .05, graph .05, graph .05;\n set border lw 1 lc rgb 'white'; \"\"\"","category":"page"},{"location":"api/#API-1","page":"API","title":"API","text":"","category":"section"},{"location":"api/#Index-1","page":"API","title":"Index","text":"","category":"section"},{"location":"api/#","page":"API","title":"API","text":"","category":"page"},{"location":"api/#Exported-symbols-1","page":"API","title":"Exported symbols","text":"","category":"section"},{"location":"api/#","page":"API","title":"API","text":"The list of Gnuplot.jl exported symbols is as follows:","category":"page"},{"location":"api/#","page":"API","title":"API","text":"@gp\n@gsp\nboxxyerror\ncontourlines\ndataset_names\ngpexec\nhist\nlinetypes\npalette\npalette_names\nsave\nsession_names\nstats\nterminals\nterminal\ntest_terminal","category":"page"},{"location":"api/#Gnuplot.@gp","page":"API","title":"Gnuplot.@gp","text":"@gp args...\n\nThe @gp macro, and its companion @gsp for 3D plots, allows to send data and commands to the gnuplot using an extremely concise syntax. The macros accepts any number of arguments, with the following meaning:\n\none, or a group of consecutive, array(s) build up a dataset. The different arrays are accessible as columns 1, 2, etc. from the gnuplot process. The number of required input arrays depends on the chosen plot style (see gnuplot documentation);\na string occurring before a dataset is interpreted as a gnuplot command (e.g. set grid);\na string occurring immediately after a dataset is interpreted as a plot element for the dataset, by which you can specify using clause, with clause, line styles, etc.. All keywords may be abbreviated following gnuplot conventions. Moreover, \"plot\" and \"splot\" can be abbreviated to \"p\" and \"s\" respectively;\nthe special symbol :-, whose meaning is to avoid starting a new plot (if given as first argument), or to avoid immediately running all commands to create the final plot (if given as last argument). Its purpose is to allow splitting one long statement into multiple (shorter) ones;\nany other symbol is interpreted as a session ID;\nan Int (>= 1) is interpreted as the plot destination in a multi-plot session (this specification applies to subsequent arguments, not previous ones);\nan input in the form \"\\$name\"=>(array1, array2, etc...) is interpreted as a named dataset. Note that the dataset name must always start with a \"$\";\nan input in the form keyword=value is interpreted as a keyword/value pair. The accepted keywords and their corresponding gnuplot commands are as follows:\nxrange=[low, high] => \"set xrange [low:high];\nyrange=[low, high] => \"set yrange [low:high];\nzrange=[low, high] => \"set zrange [low:high];\ncbrange=[low, high]=> \"set cbrange[low:high];\nkey=\"...\" => \"set key ...\";\ntitle=\"...\" => \"set title \"...\"\";\nxlabel=\"...\" => \"set xlabel \"...\"\";\nylabel=\"...\" => \"set ylabel \"...\"\";\nzlabel=\"...\" => \"set zlabel \"...\"\";\ncblabel=\"...\" => \"set cblabel \"...\"\";\nxlog=true => set logscale x;\nylog=true => set logscale y;\nzlog=true => set logscale z.\ncblog=true => set logscale cb.\n\nAll Keyword names can be abbreviated as long as the resulting name is unambiguous. E.g. you can use xr=[1,10] in place of xrange=[1,10].\n\n\n\n\n\n","category":"macro"},{"location":"api/#Gnuplot.@gsp","page":"API","title":"Gnuplot.@gsp","text":"@gsp args...\n\nThis macro accepts the same syntax as @gp, but produces a 3D plot instead of a 2D one.\n\n\n\n\n\n","category":"macro"},{"location":"api/#Gnuplot.boxxyerror","page":"API","title":"Gnuplot.boxxyerror","text":"boxxyerror(x, y; xmin=NaN, ymin=NaN, xmax=NaN, ymax=NaN, cartesian=false)\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.contourlines","page":"API","title":"Gnuplot.contourlines","text":"contourlines(x::Vector{Float64}, y::Vector{Float64}, h::Matrix{Float64}; cntrparam=\"level auto 10\")\n\nCompute paths of contour lines for 2D data, and return a vector of IsoContourLines object.\n\nArguments:\n\nx, y: Coordinates;\nh: the levels on which iso contour lines are to be calculated\ncntrparam: settings to compute contour line paths (see gnuplot documentation for cntrparam).\n\nExample\n\nx = randn(5000);\ny = randn(5000);\nh = hist(x, y, nbins1=20, nbins2=20);\nclines = contourlines(h.bins1, h.bins2, h.counts, cntrparam=\"levels discrete 15, 30, 45\");\n@gp \"set size ratio -1\"\nfor i in 1:length(clines)\n @gp :- clines[i].data \"w l t '$(clines[i].z)' dt $i\"\nend\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.dataset_names","page":"API","title":"Gnuplot.dataset_names","text":"dataset_names(sid::Symbol)\ndataset_names()\n\nReturn a vector with all dataset names for the sid session. If sid is not provided the default session is considered.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.gpexec","page":"API","title":"Gnuplot.gpexec","text":"gpexec(sid::Symbol, command::String)\ngpexec(command::String)\n\nExecute the gnuplot command command on the underlying gnuplot process of the sid session, and return the results as a Vector{String}. If a gnuplot error arises it is propagated as an ErrorException.\n\nThe the sid argument is not provided, the default session is considered.\n\nExamples:\n\ngpexec(\"print GPVAL_TERM\")\ngpexec(\"plot sin(x)\")\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.hist","page":"API","title":"Gnuplot.hist","text":"hist(v::Vector{T}; range=extrema(v), bs=NaN, nbins=0, pad=true) where T <: Number\n\nCalculates the histogram of the values in v and returns a Histogram1D structure.\n\nArguments\n\nv: a vector of values to compute the histogra;\nrange: values of the left edge of the first bin and of the right edge of the last bin;\nbs: size of histogram bins;\nnbins: number of bins in the histogram;\npad: if true add one dummy bins with zero counts before the first bin and after the last.\n\nIf bs is given nbins is ignored.\n\nExample\n\nv = randn(1000)\nh = hist(v, bs=0.5)\n@gp h # preview\n@gp h.bins h.counts \"w histep notit\"\n\n\n\n\n\nhist(v1::Vector{T1 <: Number}, v2::Vector{T2 <: Number}; range1=[NaN,NaN], bs1=NaN, nbins1=0, range2=[NaN,NaN], bs2=NaN, nbins2=0)\n\nCalculates the 2D histogram of the values in v1 and v2 and returns a Histogram2D structure.\n\nArguments\n\nv1: a vector of values along the first dimension;\nv2: a vector of values along the second dimension;\nrange1: values of the left edge of the first bin and of the right edge of the last bin, along the first dimension;\nrange1: values of the left edge of the first bin and of the right edge of the last bin, along the second dimension;\nbs1: size of histogram bins along the first dimension;\nbs2: size of histogram bins along the second dimension;\nnbins1: number of bins along the first dimension;\nnbins2: number of bins along the second dimension;\n\nIf bs1 (bs2) is given nbins1 (nbins2) is ignored.\n\nExample\n\nv1 = randn(1000)\nv2 = randn(1000)\nh = hist(v1, v2, bs1=0.5, bs2=0.5)\n@gp h # preview\n@gp \"set size ratio -1\" \"set auto fix\" h.bins1 h.bins2 h.counts \"w image notit\"\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.linetypes","page":"API","title":"Gnuplot.linetypes","text":"linetypes(cmap::ColorScheme; rev=false)\nlinetypes(s::Symbol; rev=false)\n\nConvert a ColorScheme object into a string containing the gnuplot commands to set up linetype colors.\n\nIf the argument is a Symbol it is interpreted as the name of one of the predefined schemes in ColorSchemes. If rev=true the line colors are reversed.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.palette","page":"API","title":"Gnuplot.palette","text":"palette(cmap::ColorScheme; rev=false)\npalette(s::Symbol; rev=false)\n\nConvert a ColorScheme object into a string containing the gnuplot commands to set up the corresponding palette.\n\nIf the argument is a Symbol it is interpreted as the name of one of the predefined schemes in ColorSchemes. If rev=true the palette is reversed.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.palette_names","page":"API","title":"Gnuplot.palette_names","text":"palette_names()\n\nReturn a vector with all available color schemes for the palette and linetypes function.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.save","page":"API","title":"Gnuplot.save","text":"save(sid::Symbol; term=\"\", output=\"\")\nsave(sid::Symbol, script_filename::String, ;term=\"\", output=\"\")\nsave(; term=\"\", output=\"\")\nsave(script_filename::String ;term=\"\", output=\"\")\n\nExport a (multi-)plot into the external file name provided in the output= keyword. The gnuplot terminal to use is provided through the term= keyword.\n\nIf the script_filename argument is provided a gnuplot script will be written in place of the output image. The latter can then be used in a pure gnuplot session (Julia is no longer needed) to generate exactly the same original plot.\n\nIf the sid argument is provided the operation applies to the corresponding session.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.session_names","page":"API","title":"Gnuplot.session_names","text":"session_names()\n\nReturn a vector with all currently active sessions.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.stats","page":"API","title":"Gnuplot.stats","text":"stats(sid::Symbol,name::String)\nstats(name::String)\nstats(sid::Symbol)\nstats()\n\nPrint a statistical summary for the name dataset, belonging to sid session. If name is not provdied a summary is printed for each dataset in the session. If sid is not provided the default session is considered.\n\nThis function is actually a wrapper for the gnuplot command stats.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.terminals","page":"API","title":"Gnuplot.terminals","text":"terminals()\n\nReturn a Vector{String} with the names of all the available gnuplot terminals.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.terminal","page":"API","title":"Gnuplot.terminal","text":"terminal(sid::Symbol)\nterminal()\n\nReturn a String with the current gnuplot terminal (and its options) of the process associated to session sid, or to the default session (if sid is not provided).\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.test_terminal","page":"API","title":"Gnuplot.test_terminal","text":"test_terminal(term=nothing; linetypes=nothing, palette=nothing)\n\nRun the test and test palette commands on a gnuplot terminal.\n\nIf no term is given it will use the default terminal. If lt and pal are given they are used as input to the linetypes and palette function repsetcively to load the associated color scheme.\n\nExamples\n\ntest_terminal()\ntest_terminal(\"wxt\", lt=:rust, pal=:viridis)\n\n\n\n\n\n","category":"function"},{"location":"api/#Non-exported-symbols-1","page":"API","title":"Non-exported symbols","text":"","category":"section"},{"location":"api/#","page":"API","title":"API","text":"The following functions are not exported by the Gnuplot.jl package since they are typically not used in every day work, or aimed to debugging purposes. Still, they can be useful in some case, hence they are documented here.","category":"page"},{"location":"api/#","page":"API","title":"API","text":"In order to call these functions you should add the Gnuplot. prefix to the function name.","category":"page"},{"location":"api/#","page":"API","title":"API","text":"Gnuplot.Histogram1D\nGnuplot.Histogram2D\nGnuplot.IsoContourLines\nGnuplot.Options\nGnuplot.Path2d\nGnuplot.gpversion\nGnuplot.quit\nGnuplot.quitall\nGnuplot.version","category":"page"},{"location":"api/#Gnuplot.Histogram1D","page":"API","title":"Gnuplot.Histogram1D","text":"Histogram1D\n\nA 1D histogram data.\n\nFields\n\nbins::Vector{Float64}: bin center values;\ncounts::Vector{Float64}: counts in the bins;\nbinsize::Float64: size of each bin;\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.Histogram2D","page":"API","title":"Gnuplot.Histogram2D","text":"Histogram2D\n\nA 2D histogram data.\n\nFields\n\nbins1::Vector{Float64}: bin center values along first dimension;\nbins2::Vector{Float64}: bin center values along second dimension;\ncounts::Vector{Float64}: counts in the bins;\nbinsize1::Float64: size of each bin along first dimension;\nbinsize2::Float64: size of each bin along second dimension;\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.IsoContourLines","page":"API","title":"Gnuplot.IsoContourLines","text":"IsoContourLines\n\nCoordinates of all contour lines of a given level.\n\nFields\n\npaths::Vector{Path2d}: vector of Path2d objects, one for each continuous path;\ndata::Vector{String}: vector with string representation of all paths (ready to be sent to gnuplot);\nz::Float64: level of the contour lines.\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.Options","page":"API","title":"Gnuplot.Options","text":"Options\n\nStructure containing the package global options, accessible through Gnuplot.options.\n\nFields\n\ndry::Bool: whether to use dry sessions, i.e. without an underlying Gnuplot process (default: false)\ncmd::String: command to start the Gnuplot process (default: \"gnuplot\")\ndefault::Symbol: default session name (default: :default)\ninit::Vector{String}: commands to initialize the gnuplot session (e.g., to set default terminal)\nverbose::Bool: verbosity flag (default: false)\npreferred_format::Symbol: preferred format to send data to gnuplot. Value must be one of:\nbin: fastest solution for large datasets, but uses temporary files;\ntext: may be slow for large datasets, but no temporary file is involved;\nauto (default) automatically choose the best strategy.\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.Path2d","page":"API","title":"Gnuplot.Path2d","text":"Path2d\n\nA path in 2D.\n\nFields\n\nx::Vector{Float64}\ny::Vector{Float64}\n\n\n\n\n\n","category":"type"},{"location":"api/#Gnuplot.gpversion","page":"API","title":"Gnuplot.gpversion","text":"Gnuplot.gpversion()\n\nReturn the gnuplot application version.\n\nRaise an error if version is < 5.0 (required to use data blocks).\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.quit","page":"API","title":"Gnuplot.quit","text":"Gnuplot.quit(sid::Symbol)\n\nQuit the session identified by sid and the associated gnuplot process (if any).\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.quitall","page":"API","title":"Gnuplot.quitall","text":"Gnuplot.quitall()\n\nQuit all the sessions and the associated gnuplot processes.\n\n\n\n\n\n","category":"function"},{"location":"api/#Gnuplot.version","page":"API","title":"Gnuplot.version","text":"Gnuplot.version()\n\nReturn the Gnuplot.jl package version.\n\n\n\n\n\n","category":"function"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"using Gnuplot\nGnuplot.quitall()\nmkpath(\"assets\")\nGnuplot.splash(\"assets/logo.png\")\nsaveas(file) = save(term=\"pngcairo size 480,360 fontscale 0.8\", output=\"assets/$(file).png\")\nempty!(Gnuplot.options.init)\ngpexec(\"set term unknown\")","category":"page"},{"location":"basic/#Basic-usage-1","page":"Basic usage","title":"Basic usage","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The main purpose of the Gnuplot.jl package is to send data and commands to the underlying gnuplot process, in order to generate plots. Unlike other packages, however, the actual commands to plot, or the plot attributes, are not specified through function calls. This is what makes Gnuplot.jl easy to learn and use: there are no functions or keywords names to memorize[1].","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The most important symbols exported by the package are the @gp (for 2D plots) and @gsp (for 3D plots) macros. The simplemost example is as follows:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp 1:20\nsaveas(\"ex000\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Both macros accept any number of arguments, whose meaning is interpreted as follows:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"one, or a group of consecutive, array(s) build up a dataset. The different arrays are accessible as columns 1, 2, etc. from the gnuplot process. The number of required input arrays depends on the chosen plot style (see gnuplot documentation);\na string occurring before a dataset is interpreted as a gnuplot command (e.g. set grid);\na string occurring immediately after a dataset is interpreted as a plot element for the dataset, by which you can specify using clause, with clause, line styles, etc.;\nthe special symbol :-, whose meaning is to avoid starting a new plot (if given as first argument), or to avoid immediately running all commands to create the final plot (if given as last argument). Its purpose is to allow splitting one long statement into multiple (shorter) ones.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The above list shows all the fundamental concepts to follow the examples presented below. The @gp and @gsp macros also accepts further arguments, but their use will be discussed in Advanced usage.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"[1]: a previous knowledge of gnuplot usage is, nevertheless, required.","category":"page"},{"location":"basic/#plots2d-1","page":"Basic usage","title":"2D plots","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Here we will show a few examples to generate 2D plots. The examples are intentionally very simple to highlight the behavior of Gnuplot.jl. See Examples for more complex ones.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Remember to run:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"using Gnuplot","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"before running the examples.","category":"page"},{"location":"basic/#Simple-examples-involving-just-gnuplot-commands:-1","page":"Basic usage","title":"Simple examples involving just gnuplot commands:","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Plot-a-sinusoid:-1","page":"Basic usage","title":"Plot a sinusoid:","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"plot sin(x)\"\nsaveas(\"ex001\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Plot-two-curves:-1","page":"Basic usage","title":"Plot two curves:","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"set key left\" \"plot sin(x)\" \"pl cos(x)\"\nsaveas(\"ex002\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"note: Note\nNote that all gnuplot commands can be abbreviated as long as the resulting string is not ambiguous. In the example above we used pl in place of plot.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Split-a-@gp-call-in-three-statements:-1","page":"Basic usage","title":"Split a @gp call in three statements:","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"set grid\" :-\n@gp :- \"p sin(x)\" :-\n@gp :- \"plo cos(x)\"\nsaveas(\"ex003\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"note: Note\nThe trailing :- symbol means the plot will not be updated until the last statement.","category":"page"},{"location":"basic/#Send-data-from-Julia-to-gnuplot:-1","page":"Basic usage","title":"Send data from Julia to gnuplot:","text":"","category":"section"},{"location":"basic/#Plot-a-parabola-1","page":"Basic usage","title":"Plot a parabola","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp (1:20).^2\nsaveas(\"ex004\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Plot-a-parabola-with-scaled-x-axis,-lines-and-legend-1","page":"Basic usage","title":"Plot a parabola with scaled x axis, lines and legend","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"x = 1:20\n@gp \"set key left\" x ./ 20 x.^2 \"with lines tit 'Parabola'\"\nsaveas(\"ex005\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Multiple-datasets,-logarithmic-axis,-labels-and-colors,-etc.-1","page":"Basic usage","title":"Multiple datasets, logarithmic axis, labels and colors, etc.","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"x = 1:0.1:10\n@gp \"set grid\" \"set key left\" \"set logscale y\"\n@gp :- \"set title 'Plot title'\" \"set label 'X label'\" \"set xrange [0:*]\"\n@gp :- x x.^0.5 \"w l tit 'Pow 0.5' dt 2 lw 2 lc rgb 'red'\"\n@gp :- x x \"w l tit 'Pow 1' dt 1 lw 3 lc rgb 'blue'\"\n@gp :- x x.^2 \"w l tit 'Pow 2' dt 3 lw 2 lc rgb 'purple'\"\nsaveas(\"ex006\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"note: Note\nThe above example lacks the trailing :- symbol. This means the plot will be updated at each command, adding one curve at a time.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"","category":"page"},{"location":"basic/#Keywords-for-common-commands-1","page":"Basic usage","title":"Keywords for common commands","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"In order to avoid typing long, and very frequently used gnuplot commands, Gnuplot.jl provides a few keywords which can be used in both @gp and @sgp calls:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"xrange=[low, high] => \"set xrange [low:high];\nyrange=[low, high] => \"set yrange [low:high];\nzrange=[low, high] => \"set zrange [low:high];\ncbrange=[low, high]=> \"set cbrange[low:high];\nkey=\"...\" => \"set key ...\";\ntitle=\"...\" => \"set title \\\"...\\\"\";\nxlabel=\"...\" => \"set xlabel \\\"...\\\"\";\nylabel=\"...\" => \"set ylabel \\\"...\\\"\";\nzlabel=\"...\" => \"set zlabel \\\"...\\\"\";\ncblabel=\"...\" => \"set cblabel \\\"...\\\"\";\nxlog=true => set logscale x;\nylog=true => set logscale y;\nzlog=true => set logscale z;","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"All such keywords can be abbreviated to unambiguous names.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"By using the above keywords the first lines of the previous example:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"set grid\" \"set key left\" \"set logscale y\"\n@gp :- \"set title 'Plot title'\" \"set label 'X label'\" \"set xrange [0:*]\"","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"can be replaced with a shorter version:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp \"set grid\" k=\"left\" ylog=true\n@gp :- tit=\"Plot title\" xlab=\"X label\" xr=[0,NaN]","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"where NaN in the xrange keyword means using axis autoscaling.","category":"page"},{"location":"basic/#Plot-images-1","page":"Basic usage","title":"Plot images","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Gnuplot.jl can also display images, i.e. 2D arrays:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"img = randn(Float64, 30, 50)\nimg[10,:] .= -5\n@gp img \"w image notit\"\nsaveas(\"ex007a\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Note that the first index in the img matrix corresponds to the x coordinate when the image is displayed.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"If the orientation is not the correct one you may adjust it with the gnuplot rotate= keyword (the following example requires the TestImages package to be installed):","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"using TestImages\nimg = testimage(\"lighthouse\");\n@gp \"set size square\" \"set autoscale fix\" img \"rotate=-90deg with rgbimage notit\"\nsaveas(\"ex007b\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"To display a gray image use with image in place of with rgbimage, e.g.:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"img = testimage(\"walkbridge\");\n@gp palette(:viridis) \"set size square\" \"set autoscale fix\" img \"rotate=-0.5pi with image notit\"\nsaveas(\"ex007c\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Note that we used a custom palette (:lapaz, see Palettes and line types) and the rotation angle has been expressed in radians (-0.5pi).","category":"page"},{"location":"basic/#plots3d-1","page":"Basic usage","title":"3D plots","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"3D plots follow the same rules as 2D ones, just replace the @gp macro with @gsp and add the required columns (according to the plotting style).","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"E.g., to plot a spiral increasing in size along the X direction:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"x = 0:0.1:10pi\n@gsp cbr=[-1,1].*30 x sin.(x) .* x cos.(x) .* x x./20 \"w p pt 7 ps var lc pal\"\nsaveas(\"ex008\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Note that the fourth array in the dataset, x./20, is used as by gnuplot as point size (ps var). Also note that all the keywords discussed above can also be used in 3D plots.","category":"page"},{"location":"basic/#Palettes-and-line-types-1","page":"Basic usage","title":"Palettes and line types","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The Gnuplot.jl package comes with all the ColorSchemes palettes readily available.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"A gnuplot-compliant palette can be retrieved with palette(), and used as any other command. The previous example may use an alternative palette with:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"x = 0:0.1:10pi\n@gsp palette(:viridis) cbr=[-1,1].*30 :-\n@gsp :- x sin.(x) .* x cos.(x) .* x x./20 \"w p pt 7 ps var lc pal\"\nsaveas(\"ex008a\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The ColorSchemes palettes can also be used to generate line types (actually just line colors), by means of the linetypes() function, e.g.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"@gp linetypes(:deepsea)\nx = 1:0.1:4pi\nfor i in 1:5\n @gp :- x i.* sin.(x) \"w l notit lw 5\"\nend\nsaveas(\"ex009\") # hide","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(Image: )","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The list of all available palette can be retrieved with palette_names():","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"palette_names()","category":"page"},{"location":"basic/#Exporting-plots-to-files-1","page":"Basic usage","title":"Exporting plots to files","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Gnuplot.jl to export all plots (as well as multiplots, see Multiplot) to an external file using one of the many available gnuplot terminals. To check which terminals are available in your platform type:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"terminals()","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"(see also terminal() to check your current terminal).","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Once you choose the proper terminal (i.e. format of the exported file), use the save() function to export. As an example, all the plots in this page have been saved with:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"save(term=\"pngcairo size 480,360 fontscale 0.8\", output=\"assets/output.png\")","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Note that you can pass both the terminal name and its options via the term= keyword. See Gnuplot terminals for further info on the terminals.","category":"page"},{"location":"basic/#Gnuplot-scripts-1","page":"Basic usage","title":"Gnuplot scripts","text":"","category":"section"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"Besides exporting plots in a file Gnuplot.jl can also save a script, i.e. a file containing the minimum set of data and commands required to re-create a figure using just gnuplot.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"The script allows a complete decoupling of plot data and aethetics, from the Julia code used to generate them. With scripts you can:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"modify all aesthetic details of a plot without re-running the (possibly complex and time-consuming) code used to generate it;\nshare both data and plots with colleagues without the need to share the Julia code.","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"To generate a script for one of the examples above use:","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"save(\"script.gp\")","category":"page"},{"location":"basic/#","page":"Basic usage","title":"Basic usage","text":"after the plot has been displayed. Note that when images or large datasets are involved, save() may store the data in binary files under a directory named