Docstrings updated

This commit is contained in:
Giorgio Calderone 2020-04-01 19:35:54 +02:00
parent fbc148db96
commit 4a1284117b
3 changed files with 34 additions and 21 deletions

View File

@ -5,3 +5,15 @@ An exhaustive gallery of example is available here:
[https://lazarusa.github.io/gnuplot-examples/](https://lazarusa.github.io/gnuplot-examples/)
Further `gnuplot` examples can be found here: [http://www.gnuplotting.org/](http://www.gnuplotting.org/)
```julia
Gnuplot.quitall()
@gp "set term wxt noenhanced size 600,300" :-
@gp :- "set margin 0" "set border 0" "unset tics" :-
@gp :- xr=[-0.3,1.7] yr=[-0.3,1.1] :-
@gp :- "set origin 0,0" "set size 1,1" :-
@gp :- "set label 1 at graph 1,1 right offset character -1,-1 font 'Verdana,20' tc rgb '#4d64ae' ' Ver: " * string(Gnuplot.version()) * "' " :-
@gp :- "set arrow 1 from graph 0.05, 0.15 to graph 0.95, 0.15 size 0.2,20,60 noborder lw 9 lc rgb '#4d64ae'" :-
@gp :- "set arrow 2 from graph 0.15, 0.05 to graph 0.15, 0.95 size 0.2,20,60 noborder lw 9 lc rgb '#4d64ae'" :-
@gp :- ["0.35 0.65 @ 13253682", "0.85 0.65 g 3774278", "1.3 0.65 p 9591203"] "w labels notit font 'Mono,160' tc rgb var"
save(term="pngcairo noenhanced size 600,300", output="splash.png")
```

View File

@ -1,9 +1,5 @@
# Tips
# Useful terminals
This page collects useful tips in using **Gnuplot.jl**.
## Which terminal should I use ?
Gnuplot provides dozens of terminals to display plots or export them into files (see [`terminals()`](@ref) to get a list of enabled terminals on your platform). This section discuss a few tips on how to use the most common terminals.
To use a specific terminal for interactive use you may either add it as initialization command for all new session with (see [Options](@ref)):
@ -17,7 +13,7 @@ gpexec("set term wxt")
See official [gnuplot documentation](http://gnuplot.sourceforge.net/documentation.html) for further info on terminals and their options.
### Interactive terminals (`wxt` and `qt`)
## Interactive terminals (`wxt` and `qt`)
The multiplatform `wxt` and `qt` terminals are among the most widely used ones for their nicely looking outputs on display and for their interactive capabilities.
You may set them as terminal with:
@ -33,8 +29,8 @@ or
Press the `h` key on the window to display an help message with all available keyboard shortcuts. In particular press `6` to enable printing plot coordinates on Julia stdout (ensure mouse is enabled with `m`).
### Plot in a terminal (`dumb`, `sixel` and `sixelgd`)
Gnuplot supports plotting in a terminal application, with no need for X11 or other GUI support, via the `dumb`, `sixel` and `sixelgd` terminals. These are useful when you run Julia on a remote shell through `ssh`. You may set these terminals with one of the following command:
## Plot in a terminal application (`dumb`, `sixel` and `sixelgd`)
Gnuplot supports plotting in a terminal application, with no need for X11 or other GUI support, via the `dumb`, `sixel` and `sixelgd` terminals. These are extremely useful when you run Julia on a remote shell through `ssh`, with no X11 forwarding. You may set these terminals with one of the following command:
```
"set term dumb"
"set term sixel"
@ -43,10 +39,10 @@ Gnuplot supports plotting in a terminal application, with no need for X11 or oth
The `dumb` terminal uses ASCII characters to draw a plot, while `sixel` and `sixelgd` actually use bitmaps (but require Sixel support to be enabled in the terminal, e.g. `xterm -ti vt340`). A sixel plot on `xterm` looks as follows:
![](assets/sixelgd.png)
The above terminals are available if gnuplot has been compiled with the `--with-bitmap-terminals` option enabled. Also, `sixelgd` requires support for Libgd to be enabled.
The above terminals are available if gnuplot has been compiled with the `--with-bitmap-terminals` option enabled and Libgd (only for `sixelgd`).
### Export to image files
## Export to image files
Gnuplot provides dozens of terminals able to export on files. Examples are:
- `cairopng` to export PNG files;
@ -54,7 +50,7 @@ Gnuplot provides dozens of terminals able to export on files. Examples are:
- `jpeg` for JPG;
- `gif` for GIF (see [Animations](@ref)).
All the above terminals support the `size` and `fontscale` options to quickly adjust the size of the rasterized image and of the font respectively. E.g.:
All the above terminals support the `size` and `fontscale` options to quickly adjust the size of the rasterized image and the size of the font respectively. E.g.:
```julia
save(term="pngcairo size 480,360 fontscale 0.8", output="output.png")
```
@ -62,23 +58,28 @@ save(term="pngcairo size 480,360 fontscale 0.8", output="output.png")
Gnuplot is also able to export vector (i.e. non-raster) plots through the `svg` terminal.
Finally, the `cairolatex` terminal allows to produce high quality plots by splitting the output into a PDF file (containing a rasterized image of a plot) and a `.tex` file (containing all the text as ``\LaTeX`` code). The following example shows how to write plot tics and an equation in ``\LaTeX``:
## The `cairolatex` terminal
The `cairolatex` terminal allows to produce high quality plots by splitting the output into a PDF file (containing a rasterized image of a plot) and a `.tex` file (containing all the text as ``\LaTeX`` code). The following example shows how to write plot tics and an equation in ``\LaTeX``:
```julia
x = LinRange(-2pi, 2pi, 1000)
@gp t="Polynomial approximation of sin(x)" "set style fill transparent solid 0.6 noborder"
@gp :- raw"""set xtics ('$-\pi$' -pi, '$-\pi/2$' -pi/2, 0, '$\pi/2$' pi/2, '$\pi$' pi)"""
@gp :- xr=3.8.*[-1, 1] yr=[-1.5,1.5] key="box opaque left horiz" linetypes(:Blues_3) "set grid front"
latex = raw"""\begin{minipage}[c]{\textwidth}\begin{equation*} \sin(x) = \sum_0^{+\infty} \frac{(-1)^n}{(2n + 1)!} x^{2n+1} \end{equation*} \end{minipage}"""
latex = raw"""\begin{minipage}[c]{\textwidth}\begin{equation*}""" *
raw"""\sin(x) = \sum_0^{+\infty} \frac{(-1)^n}{(2n + 1)!} x^{2n+1}""" *
raw"""\end{equation*} \end{minipage}"""
@gp :- "set label at graph 0.62,0.2 front center '$latex'"
@gp :- x sin.(x) x "w filledcurve t 'n=0' lt 1"
@gp :- x sin.(x) x .- x.^3/6 "w filledcurve t 'n=1' lt 2"
@gp :- x sin.(x) x .- x.^3/6 .+ x.^5/120 "w filledcurve t 'n=2' lt 3"
@gp :- x sin.(x) x .- x.^3/6 .+ x.^5/120 .- x.^7/5040 "w filledcurve t 'n=3' lt 4"
@gp :- x sin.(x) "w l t 'sin(x)' lw 2 lc rgb 'black'"
approx = fill(0., length(x));
@gp :- x sin.(x) approx .+= x "w filledcurve t 'n=0' lt 1"
@gp :- x sin.(x) approx .+= -x.^3/6 "w filledcurve t 'n=1' lt 2"
@gp :- x sin.(x) approx .+= x.^5/120 "w filledcurve t 'n=2' lt 3"
@gp :- x sin.(x) approx .+= -x.^7/5040 "w filledcurve t 'n=3' lt 4"
@gp :- x sin.(x) "w l t 'sin(x)' lw 2 lc rgb 'black'"
save(term="cairolatex pdf input color dashed size 5in,3.3in", output="test.tex")
```
!!! warning
If you add a path in the `output=` keyword this will also be copied in the the `.tex` file. I suggest to use just filenames, with no path, in order to avoid possible errors when compiling ``\LaTeX`` code.
The two output files (`test.tex` and `test.pdf`) can then be included in a ``\LaTeX`` file as follows:
```latex
\documentclass{article}

View File

@ -1206,7 +1206,7 @@ function splash(outputfile="")
elseif "aqua" in terms
gpexec(gp, "set term aqua noenhanced size 600,300")
else
@warn "None of the `wxt`, `qt` and `aqua` terminals are available. Output may look strange.."
@warn "None of the `wxt`, `qt` and `aqua` terminals are available. Output may look strange..."
end
else
gpexec(gp, "set term unknown")