Docstrings updated
This commit is contained in:
parent
59c8f2dca6
commit
30af7755c0
@ -1,12 +1,6 @@
|
||||
# Advanced techniques
|
||||
|
||||
Here we will show a few advanced techniques for data visualization using **Gnuplot.jl**. The new concepts introduced in the examples are as follows:
|
||||
|
||||
- a name can be associated to a dataset, in order to use it multiple times in a plot while sending it only once to gnuplot. A dataset name must begin with a `$`;
|
||||
|
||||
- gnuplot is able to generate multiplot, i.e. a single figure containing multiple plots. Each plot is identified by a numeric ID, starting from 1;
|
||||
|
||||
- **Gnuplot.jl** is able to handle multiple sessions, i.e. multiple gnuplot processes running simultaneously. Each session is identified by a symbol. If the session ID is not specified the `:default` session is considered.
|
||||
Here we will show a few advanced techniques for data visualization using **Gnuplot.jl**.
|
||||
|
||||
|
||||
```@setup abc
|
||||
@ -20,12 +14,14 @@ Gnuplot.exec("set term unknown")
|
||||
|
||||
|
||||
## Named datasets
|
||||
A named dataset can be used multiple times in a plot, avoiding sending to gnuplot the same data multiple times. A dataset name must always start with a `$`, and the dataset is defined as a `Pair{String, Tuple}`, e.g.:
|
||||
|
||||
A dataset may have an associated name whose purpose is to use it multiple times for plotting, while sending it only once to gnuplot. A dataset name must begin with a `$`.
|
||||
|
||||
A named dataset is defined as a `Pair{String, Tuple}`, e.g.:
|
||||
```julia
|
||||
"\$name" => (1:10,)
|
||||
```
|
||||
|
||||
A named dataset can be used as an argument to both `@gp` and `gsp`, e.g.:
|
||||
and can be used as an argument to both `@gp` and `gsp`, e.g.:
|
||||
```@example abc
|
||||
x = range(-2pi, stop=2pi, length=100);
|
||||
y = sin.(x)
|
||||
@ -107,6 +103,33 @@ saveas("ex012") # hide
|
||||
|
||||
|
||||
## Multiple sessions
|
||||
|
||||
**Gnuplot.jl** can handle multiple sessions, i.e. multiple gnuplot processes running simultaneously. Each session is identified by a symbol.
|
||||
|
||||
In order to redirect commands to a specific session simply insert a symbol into your `@gp` or `@gsp` call, e.g.:
|
||||
```@example abc
|
||||
@gp :GP1 "plot sin(x)" # opens first window
|
||||
@gp :GP2 "plot sin(x)" # opens secondo window
|
||||
@gp :- :GP1 "plot cos(x)" # add a plot on first window
|
||||
```
|
||||
If the session ID is not specified the `:default` session is considered.
|
||||
|
||||
The names of all current sessions can be retrieved with [`session_names()`](@ref):
|
||||
```@repl abc
|
||||
println(session_names())
|
||||
```
|
||||
|
||||
To quit a specific session use [`Gnuplot.quit()`](@ref):
|
||||
```@repl abc
|
||||
Gnuplot.quit(:GP1)
|
||||
```
|
||||
The output value is the exit status of the underlying gnuplot process.
|
||||
|
||||
You may also quit all active sessions at once with [`Gnuplot.quitall()`](@ref):
|
||||
```@repl abc
|
||||
Gnuplot.quitall()
|
||||
```
|
||||
|
||||
## Histograms (1D)
|
||||
## Histograms (2D)
|
||||
## Contour lines
|
||||
|
||||
@ -154,18 +154,18 @@ If the orientation is not the correct one you may adjust it with the gnuplot `ro
|
||||
using TestImages
|
||||
img = testimage("lighthouse");
|
||||
@gp "set size square" "set autoscale fix" img "rotate=-90deg with rgbimage notit"
|
||||
save(term="jpeg size 480,360", output="assets/ex007b.jpg") # hide
|
||||
saveas("ex007b") # hide
|
||||
```
|
||||

|
||||

|
||||
|
||||
|
||||
To display a gray image use `with image` in place of `with rgbimage`, e.g.:
|
||||
```@example abc
|
||||
img = testimage("walkbridge");
|
||||
@gp palette(:lapaz) "set size square" "set autoscale fix" img "rotate=-0.5pi with image notit"
|
||||
save(term="jpeg size 480,360", output="assets/ex007c.jpg") # hide
|
||||
saveas("ex007c") # hide
|
||||
```
|
||||

|
||||

|
||||
|
||||
Note that we used a custom palette (`:lapaz`, see [Palettes and line types](@ref)) and the rotation angle has been expressed in radians (`-0.5pi`).
|
||||
|
||||
@ -184,19 +184,21 @@ saveas("ex008") # hide
|
||||
|
||||
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.
|
||||
|
||||
|
||||
## Palettes and line types
|
||||
The **Gnuplot.jl** package comes with all the [ColorSchemes](https://juliagraphics.github.io/ColorSchemes.jl/stable/basics/#Pre-defined-schemes-1) palettes readily available.
|
||||
|
||||
A gnuplot-compliant palette can be retrieved with `palette()`, and used as any other command. The previous example may use an alternative palette with:
|
||||
A gnuplot-compliant palette can be retrieved with [`palette()`](@ref), and used as any other command. The previous example may use an alternative palette with:
|
||||
```@example abc
|
||||
x = 0:0.1:10pi
|
||||
@gsp palette(:viridis) cbr=[-1,1].*30 x sin.(x) .* x cos.(x) .* x x./20 "w p pt 7 ps var lc pal"
|
||||
@gsp palette(:viridis) cbr=[-1,1].*30 :-
|
||||
@gsp :- x sin.(x) .* x cos.(x) .* x x./20 "w p pt 7 ps var lc pal"
|
||||
saveas("ex008a") # hide
|
||||
```
|
||||

|
||||
|
||||
|
||||
The [ColorSchemes](https://juliagraphics.github.io/ColorSchemes.jl/stable/basics/#Pre-defined-schemes-1) palettes can also be used to generate line types (actually just line colors), by means of the `linetypes()` function, e.g.
|
||||
The [ColorSchemes](https://juliagraphics.github.io/ColorSchemes.jl/stable/basics/#Pre-defined-schemes-1) palettes can also be used to generate line types (actually just line colors), by means of the [`linetypes()`](@ref) function, e.g.
|
||||
```@example abc
|
||||
@gp linetypes(:deepsea)
|
||||
x = 1:0.1:4pi
|
||||
@ -207,12 +209,15 @@ saveas("ex009") # hide
|
||||
```
|
||||

|
||||
|
||||
|
||||
The list of all available palette can be retrieved with [`palette_names()`](@ref):
|
||||
```@repl abc
|
||||
palette_names()
|
||||
```
|
||||
|
||||
|
||||
## Exporting plots to files
|
||||
|
||||
The `save()` function allows to export all plots (as well as multiplots, see [Multiplot](@ref)) to a file using one of the many available gnuplot terminals. To check which terminals are available in your platform type `set term` in your gnuplot terminal.
|
||||
The [`save()`](@ref) function allows to export all plots (as well as multiplots, see [Multiplot](@ref)) to a file using one of the many available gnuplot terminals. To check which terminals are available in your platform type `set term` in your gnuplot terminal.
|
||||
|
||||
All plots in this page have been saved with:
|
||||
```julia
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user