This commit is contained in:
Giorgio Calderone 2020-04-17 19:07:37 +02:00
parent 05d887ac9d
commit 7fccfa2ae1
6 changed files with 50 additions and 51 deletions

View File

@ -3,10 +3,9 @@ using Gnuplot
Gnuplot.quitall() Gnuplot.quitall()
mkpath("assets") mkpath("assets")
Gnuplot.options.term = "unknown"
empty!(Gnuplot.options.init) empty!(Gnuplot.options.init)
push!( Gnuplot.options.init, "set term unknown") push!( Gnuplot.options.init, linetypes(:Set1_5, lw=1.5, ps=1.5))
empty!(Gnuplot.options.reset)
push!( Gnuplot.options.reset, linetypes(:Set1_5, lw=1.5, ps=1.5))
saveas(file) = save(term="pngcairo size 550,350 fontscale 0.8", output="assets/$(file).png") saveas(file) = save(term="pngcairo size 550,350 fontscale 0.8", output="assets/$(file).png")
``` ```

View File

@ -3,10 +3,9 @@ using Gnuplot
Gnuplot.quitall() Gnuplot.quitall()
mkpath("assets") mkpath("assets")
Gnuplot.splash("assets/logo.png") Gnuplot.splash("assets/logo.png")
Gnuplot.options.term = "unknown"
empty!(Gnuplot.options.init) empty!(Gnuplot.options.init)
push!( Gnuplot.options.init, "set term unknown") push!( Gnuplot.options.init, linetypes(:Set1_5, lw=1.5, ps=1.5))
empty!(Gnuplot.options.reset)
push!( Gnuplot.options.reset, linetypes(:Set1_5, lw=1.5, ps=1.5))
saveas(file) = save(term="pngcairo size 550,350 fontscale 0.8", output="assets/$(file).png") saveas(file) = save(term="pngcairo size 550,350 fontscale 0.8", output="assets/$(file).png")
``` ```
@ -22,8 +21,10 @@ saveas("basic000") # hide
``` ```
![](assets/basic000.png) ![](assets/basic000.png)
The plots are displayed either in an interactive window (if running in the Julia REPL), as an inline image (if running in Jupyter) or in the plot pane (if running in Juno). See [Options](@ref) and [Jupyter and Juno](@ref) for further informations.
Both macros accept any number of arguments, whose meaning is interpreted as follows:
Both the [`@gp`](@ref) and [`@gsp`](@ref) macros accept any number of arguments, whose meaning is interpreted as follows:
- 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); - 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);
@ -160,7 +161,7 @@ where `NaN` in the `xrange` keyword means using axis autoscaling.
**Gnuplot.jl** can display a 2D matrix as an image: **Gnuplot.jl** can display a 2D matrix as an image:
```@example abc ```@example abc
img = randn(Float64, 15, 5) img = randn(Float64, 10, 5)
img[10,:] .= -5 img[10,:] .= -5
@gp img "w image notit" @gp img "w image notit"
saveas("basic007a") # hide saveas("basic007a") # hide
@ -169,11 +170,11 @@ saveas("basic007a") # hide
Note that the first index in the `img` matrix corresponds to the rows in the displayed image coordinate when the image is displayed. Note that the first index in the `img` matrix corresponds to the rows in the displayed image coordinate when the image is displayed.
A simple way to remember the convention is to compare how matrix are displayed on the REPL: A simple way to remember the convention is to compare how a matrix is displayed in the REPL:
```@example abc ```@example abc
img = reshape(1:15, 5, 3) img = reshape(1:15, 5, 3)
``` ```
and their image representation, which is essentially upside down: and its image representation, which is essentially upside down:
```@example abc ```@example abc
@gp img "w image notit" @gp img "w image notit"
saveas("basic007b") # hide saveas("basic007b") # hide

View File

@ -23,6 +23,8 @@ The **Gnuplot.jl** package allows easy and fast use of [gnuplot](http://gnuplot.
- export to a huge number of formats such as `pdf`, `png`, `gif`, ``\LaTeX``, `svg`, etc. (actually all those supported by gnuplot); - export to a huge number of formats such as `pdf`, `png`, `gif`, ``\LaTeX``, `svg`, etc. (actually all those supported by gnuplot);
- compatibility with Jupyter and Juno;
- save sessions into gnuplot scripts, to enable easy plot customization and reproducibility. - save sessions into gnuplot scripts, to enable easy plot customization and reproducibility.
If you're unfamiliar with gnuplot have a look at: If you're unfamiliar with gnuplot have a look at:

View File

@ -3,10 +3,9 @@ using Gnuplot
Gnuplot.quitall() Gnuplot.quitall()
mkpath("assets") mkpath("assets")
Gnuplot.options.term = "unknown"
empty!(Gnuplot.options.init) empty!(Gnuplot.options.init)
push!( Gnuplot.options.init, "set term unknown") push!( Gnuplot.options.init, linetypes(:Set1_5, lw=1.5, ps=1.5))
empty!(Gnuplot.options.reset)
push!( Gnuplot.options.reset, linetypes(:Set1_5, lw=1.5, ps=1.5))
saveas(file) = save(term="pngcairo size 550,350 fontscale 0.8", output="assets/$(file).png") saveas(file) = save(term="pngcairo size 550,350 fontscale 0.8", output="assets/$(file).png")
``` ```
@ -17,66 +16,69 @@ The package options are stored in a global structure available in Julia as `Gnup
- `dry::Bool`: if true all new sessions will be started as [Dry sessions](@ref). Default is `false`, but if the package is not able to start a gnuplot process it will automatically switch to `true`; - `dry::Bool`: if true all new sessions will be started as [Dry sessions](@ref). Default is `false`, but if the package is not able to start a gnuplot process it will automatically switch to `true`;
- `init::Vector{String}`: initialization commands to be executed when a new session is created. Default is an empty vector. It can be used to, e.g., set a custom terminal: - `cmd::String`: command to start the gnuplot process, default value is `"gnuplot"`. Use this field to specify a custom path to the gnuplot executable;
```@repl abc
push!(Gnuplot.options.init, "set term sixelgd");
```
Note that this is option affect all the newly created sessions, not the older ones. Also note that the commands in `Gnuplot.options.init` **are not** saved in [Gnuplot scripts](@ref);
- `reset::Vector{String}`: initialization commands to be executed when a session is reset. Default is an empty vector. It can be used to, e.g., set custom linetypes or palette: - `term::String`: default terminal for interactive use (default is an empty string, i.e. use gnuplot settings). A custom terminal can be set with, e.g.:
```@repl abc ```@repl abc
push!(Gnuplot.options.reset, linetypes(:Set1_5, lw=1.5, ps=1.5)); Gnuplot.options.term = "wxt size 700,400";
``` ```
Note that this is option affect all the sessions. Also note that the commands in `Gnuplot.options.reset` **are** saved in [Gnuplot scripts](@ref);
- `verbose::Bool`: a flag to set verbosity of the package. In particular if it is `true` all communication with the underlying process will be printed on stdout. E.g.: - `term_svg::String`: terminal to save png files (default `"svg"`);
- `term_png::String`: terminal to save png files (default `"pngcairo"`);
- `init::Vector{String}`: commands to initialize the session when it is created or reset. It can be used to, e.g., set a custom linetypes or palette:
```@repl abc ```@repl abc
empty!(Gnuplot.options.reset); # hide push!(Gnuplot.options.init, linetypes(:Set1_5, lw=1.5, ps=1.5));
```
Note that this option affect all the sessions, and that all inserted commands are saved in [Gnuplot scripts](@ref);
- `verbose::Bool`: a flag to set verbosity of the package. If `true` all communication with the underlying process will be printed on stdout. E.g.:
```@repl abc
empty!(Gnuplot.options.init); # hide
gpexec("set term wxt"); # hide gpexec("set term wxt"); # hide
Gnuplot.options.verbose = true; Gnuplot.options.verbose = true;
x = 1.:10; x = 1.:10;
@gp x x.^2 "w l t 'Parabola'" @gp x x.^2 "w l t 'Parabola'"
save(term="pngcairo size 480,360 fontscale 0.8", output="output.png") save(term="pngcairo size 480,360 fontscale 0.8", output="output.png")
Gnuplot.options.verbose = false # hide Gnuplot.options.verbose = false # hide
push!(Gnuplot.options.reset, linetypes(:Set1_5, lw=1.5)); # hide push!(Gnuplot.options.init, linetypes(:Set1_5, lw=1.5)); # hide
gpexec("set term unknown"); # hide gpexec("set term unknown"); # hide
``` ```
Each line reports the package name (`GNUPLOT`), the session name (`default`), the command or string being sent to gnuplot process, and the returned response (line starting with `->`). Default value is `false`; Each line reports the package name (`GNUPLOT`), the session name (`default`), the command or string being sent to gnuplot process, and the returned response (line starting with `->`). Default value is `false`;
- `cmd::String`: command to start the gnuplot process, default value is `"gnuplot"`. If you need to specify a custom path to the gnuplot executable you may change this value;
- `default::Symbol`: default session name, i.e. the session that will be used when no session name is provided; ## Jupyter and Juno
- `preferred_format::Symbol`: preferred format to send data to gnuplot. Value must be one of:
- `bin`: provides best performances for large datasets, but uses temporary files;
- `text`: may be slow for large datasets, but no temporary file is involved;
- `auto` (default) automatically choose the best strategy.
**Gnuplot.jl** can display plots in Jupyter and Juno by exporting images in the PNG and SVG formats. To customize the terminals used to export the images set the `term_png` or `term_svg` fields of the [`Gnuplot.Options`](@ref) structure, e.g.:
```@repl abc
Gnuplot.options.term_png = "pngcairo size 700,400 linewidth 2";
Gnuplot.options.term_svg = "svg dynamic";
```
## Package initialization ## Package initialization
If you use **Gnuplot.jl** frequently you may find convenient to collect all the package settings (see [Options](@ref)) in a single place, to quickly recall them in a Julia session. I suggest to put the following code in the `.julia/config/startup.jl` initialization file (further info [here](https://docs.julialang.org/en/v1/stdlib/REPL/)): If you use **Gnuplot.jl** frequently you may find convenient to collect all the package settings (see [Options](@ref)) in a single place, to quickly recall them in a Julia session. I suggest to put the following code in the `~/.julia/config/startup.jl` initialization file (further info [here](https://docs.julialang.org/en/v1/stdlib/REPL/)):
```julia ```julia
macro gnuplotrc() macro gnuplotrc()
return :( return :(
using Gnuplot; using Revise, Gnuplot;
# Uncomment following to true if you don't have the gnuplot # Uncomment following to true if you don't have the gnuplot
# executable installed on your platform: # executable installed on your platform:
#Gnuplot.options.dry = true; #Gnuplot.options.dry = true;
# Uncomment the following and set the proper path if the # Uncomment the following and set the proper path if the
# gnuplot executable is not in your $PATH # gnuplot executable is not available in your $PATH
#Gnuplot.options.cmd = "/path/to/gnuplot"; #Gnuplot.options.cmd = "/path/to/gnuplot";
# Set the default terminal for interacitve use # Set the default terminal for interacitve use
empty!(Gnuplot.options.init); Gnuplot.options.term = "wxt size 700,400";
push!(Gnuplot.options.init, "set term wxt size 700,400");
# Set the default linetypes # Set the default linetypes
empty!(Gnuplot.options.reset); empty!(Gnuplot.options.init);
push!(Gnuplot.options.reset, linetypes(:Set1_5, lw=1.5, ps=1.5)); push!(Gnuplot.options.init, linetypes(:Set1_5, lw=1.5, ps=1.5));
# Initialize the gnuplot REPL using the provided `start_key`. # Initialize the gnuplot REPL using the provided `start_key`.
# Comment the following to disable the REPL. # Comment the following to disable the REPL.

View File

@ -3,10 +3,9 @@ using Gnuplot
Gnuplot.quitall() Gnuplot.quitall()
mkpath("assets") mkpath("assets")
Gnuplot.options.term = "unknown"
empty!(Gnuplot.options.init) empty!(Gnuplot.options.init)
push!( Gnuplot.options.init, "set term unknown") push!( Gnuplot.options.init, linetypes(:Set1_5, lw=1.5, ps=1.5))
empty!(Gnuplot.options.reset)
push!( Gnuplot.options.reset, linetypes(:Set1_5, lw=1.5, ps=1.5))
saveas(file) = save(term="pngcairo size 550,350 fontscale 0.8", output="assets/$(file).png") saveas(file) = save(term="pngcairo size 550,350 fontscale 0.8", output="assets/$(file).png")
``` ```

View File

@ -2,9 +2,9 @@
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. 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)): To use a specific terminal for interactive use you may either set it as initialization command for all new session with (see [Options](@ref)):
```julia ```julia
push!(Gnuplot.options.init, "set term wxt") Gnuplot.options.term = "wxt")
``` ```
or directly send the command to a specific session (see [Direct command execution](@ref)) or directly send the command to a specific session (see [Direct command execution](@ref))
```julia ```julia
@ -30,12 +30,8 @@ Press the `h` key on the window to display an help message with all available ke
## Plot in a terminal application (`dumb`, `sixel` and `sixelgd`) ## 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: 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.
```
"set term dumb"
"set term sixel"
"set term sixelgd"
```
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: 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) ![](assets/sixelgd.png)