Compare commits
78 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea8b71898b | ||
|
|
4bdee5f6af | ||
|
|
bbbd899c19 | ||
|
|
abcb73b70f | ||
|
|
9001d5f385 | ||
|
|
919068e797 | ||
|
|
23c3d663e8 | ||
|
|
3f40e38d72 | ||
|
|
443ef0edf7 | ||
|
|
ab927d0622 | ||
|
|
622597c589 | ||
|
|
ce00617796 | ||
|
|
e70c30dd13 | ||
|
|
799154f53c | ||
|
|
d02c211e99 | ||
|
|
67c8781f2b | ||
|
|
db8dcfc433 | ||
|
|
04484adc22 | ||
|
|
658e5f422c | ||
|
|
9327492aa1 | ||
|
|
0567acc60e | ||
|
|
74e195f290 | ||
|
|
875773fd3d | ||
|
|
53159f89e1 | ||
|
|
54db30cc32 | ||
|
|
364e5281bd | ||
|
|
e8a6b21df6 | ||
|
|
6c6b889df6 | ||
|
|
5c46e35fea | ||
|
|
34af493921 | ||
|
|
f2ef5373b0 | ||
|
|
bc74aa0db4 | ||
|
|
b7a15290d3 | ||
|
|
f62b569560 | ||
|
|
584144e2ec | ||
|
|
03953c0ad6 | ||
|
|
084dd63059 | ||
|
|
50141d1b0e | ||
|
|
83c59ae682 | ||
|
|
1877deef7f | ||
|
|
67a5583c29 | ||
|
|
69644f99ba | ||
|
|
2713f8517e | ||
|
|
2c2c74e448 | ||
|
|
6bf1b80058 | ||
|
|
671efccc17 | ||
|
|
bdeb0e45ab | ||
|
|
3e03aa27f7 | ||
|
|
dab424bfec | ||
|
|
92380bc468 | ||
|
|
4d1768e15e | ||
|
|
8e140ee998 | ||
|
|
6df834bb88 | ||
|
|
c9fa96c9eb | ||
|
|
d74715f156 | ||
|
|
2fb581b3a3 | ||
|
|
190562a322 | ||
|
|
c5d64f5d76 | ||
|
|
184206946b | ||
|
|
4405daf088 | ||
|
|
e3d9d6035e | ||
|
|
e11d93d807 | ||
|
|
6996c98d40 | ||
|
|
02e15543cd | ||
|
|
8f737205a1 | ||
|
|
deee2693df | ||
|
|
a47705be6b | ||
|
|
8a8ce1f533 | ||
|
|
e687bb3716 | ||
|
|
00ef33a8a6 | ||
|
|
3238bcea80 | ||
|
|
993633886a | ||
|
|
e33b74bf6d | ||
|
|
7e3aa2b384 | ||
|
|
c5890b6819 | ||
|
|
be273493eb | ||
|
|
b79228d7b1 | ||
|
|
bad5e12681 |
10
.travis.yml
10
.travis.yml
@ -6,15 +6,15 @@ os:
|
||||
# - osx
|
||||
|
||||
julia:
|
||||
- 1.2
|
||||
- nightly
|
||||
- 1.5
|
||||
# - nightly
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- julia: nightly
|
||||
#matrix:
|
||||
# allow_failures:
|
||||
# - julia: nightly
|
||||
|
||||
addons:
|
||||
apt:
|
||||
|
||||
67
ChangeLog.md
67
ChangeLog.md
@ -1,3 +1,68 @@
|
||||
# Version 1.4.1 (released on: )
|
||||
- New features:
|
||||
* Implicit recipes can now returns a `Vector{PlotElement}`;
|
||||
|
||||
* Allow using single quotes in output file names (#52);
|
||||
|
||||
* New function: `palette_levels()` can be used to modify palette levels before passing them to gnuplot;
|
||||
|
||||
- Bugfix:
|
||||
* Fixed `BoundsErrors` in `hist()` (#49);
|
||||
|
||||
* Fixed problem when generating documentation (#51);
|
||||
|
||||
|
||||
# Version 1.4.0 (released on: May 5, 2021)
|
||||
- New features:
|
||||
* Missing values are accepted if the input arrays have `eltype <:
|
||||
AbstractFloat`;
|
||||
|
||||
* Missing values are also accepted in calls to `hist`;
|
||||
|
||||
* VSCode and Pluto sessions are now properly handled (#35 and #43);
|
||||
|
||||
- Bugfix:
|
||||
* Multiplot were not displayed in Jupyter (#25);
|
||||
|
||||
* `gpvars()` fails if gnuplot character encoding is utf8
|
||||
(#24);
|
||||
|
||||
|
||||
# Version 1.3.0 (released on: Apr. 29, 2020)
|
||||
|
||||
- New features:
|
||||
* The new `dgrid3d()` allows to interpolate scattered 2D data on a
|
||||
2D regular grid;
|
||||
|
||||
* The `Options` structure features a new `mime` field containing a
|
||||
dictionary to map a MIME type to gnuplot terminals;
|
||||
|
||||
* The `Options` structure features a new `gpviewer` field allowing
|
||||
to choose the display behaviour (using either gnuplot
|
||||
interactive terminals or anexternal viewer such as Jupyter or
|
||||
Juno);
|
||||
|
||||
* The `save()` function now accepts a `MIME` argument in place of
|
||||
the `term=` keyword. The actual terminal is retrieved from the
|
||||
`Options.mime` dictionary;
|
||||
|
||||
* The `contourlines()` function now accepts `AbstractVector` and
|
||||
`AbstractMatrix` as arguments, rather than `Vector` and
|
||||
`Matrix`;
|
||||
|
||||
* The `contourlines()` function now accepts a `fractions` input to
|
||||
generate contours encompassing given fractions of the total
|
||||
counts in a 2D histogram;
|
||||
|
||||
* The `palette()` function now accept a boolean `smooth` keyword,
|
||||
allowing to interpolate a discrete palette into a continuous one.
|
||||
|
||||
- Breaking changes:
|
||||
* The `Options` structure no longer provides the `term_svg` and
|
||||
`term_png` fields. They have been replaced by the `mime`
|
||||
dictionary.
|
||||
|
||||
|
||||
# Version 1.2.0 (released on: Apr. 20, 2020)
|
||||
|
||||
- New features:
|
||||
@ -30,6 +95,8 @@
|
||||
returned by `hist()`), contour lines (as returned by
|
||||
`contourlines()`) and images;
|
||||
|
||||
* Implemented automatic display of plots in both Jupyter and Juno;
|
||||
|
||||
* Documentation updated;
|
||||
|
||||
|
||||
|
||||
10
Project.toml
10
Project.toml
@ -1,6 +1,6 @@
|
||||
name = "Gnuplot"
|
||||
uuid = "dc211083-a33a-5b79-959f-2ff34033469d"
|
||||
version = "1.2.0"
|
||||
version = "1.4.1"
|
||||
|
||||
[deps]
|
||||
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
|
||||
@ -14,11 +14,11 @@ StructC14N = "d2514e9c-36c4-5b8e-97e2-51e7675c221c"
|
||||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||
|
||||
[compat]
|
||||
ColorSchemes = "^3.5"
|
||||
ColorTypes = "^0.10"
|
||||
ColorSchemes = "^3.12"
|
||||
ColorTypes = "^0.11"
|
||||
Colors = "^0.12"
|
||||
DataStructures = "^0.17"
|
||||
DataStructures = "^0.18"
|
||||
ReplMaker = "^0.2"
|
||||
StatsBase = "^0.33"
|
||||
StructC14N = "^0.3"
|
||||
julia = "^1.2"
|
||||
julia = "^1.6"
|
||||
|
||||
10
README.md
10
README.md
@ -3,10 +3,10 @@
|
||||
|
||||
[](https://travis-ci.org/gcalderone/Gnuplot.jl)
|
||||
[](LICENSE.md)
|
||||
[](https://gcalderone.github.io/Gnuplot.jl/v1.2.0/)
|
||||
[](https://gcalderone.github.io/Gnuplot.jl/v1.4.0/index.html)
|
||||
|
||||
|
||||
**Gnuplot.jl** is a simple package able to send both data and commands from Julia to an underlying [gnuplot](http://gnuplot.sourceforge.net/) process. Its main purpose it to provide a fast and powerful data visualization framework, using an extremely concise Julia syntax.
|
||||
**Gnuplot.jl** is a simple package able to send both data and commands from Julia to an underlying [gnuplot](http://gnuplot.sourceforge.net/) process. Its main purpose it to provide a fast and powerful data visualization framework, using an extremely concise Julia syntax. It also has automatic display of plots in Jupyter, Juno and VS Code.
|
||||
|
||||
|
||||
## Installation
|
||||
@ -21,9 +21,9 @@ You may check the installed **Gnuplot.jl** version with:
|
||||
```julia
|
||||
]st Gnuplot
|
||||
```
|
||||
If the displayed version is not v1.2.0 you are probably having a dependency conflict. In this case try forcing installation of the latest version with:
|
||||
If the displayed version is not v1.4.0 you are probably having a dependency conflict. In this case try forcing installation of the latest version with:
|
||||
```julia
|
||||
]add Gnuplot@1.2.0
|
||||
]add Gnuplot@1.4.0
|
||||
```
|
||||
and check which package is causing the conflict.
|
||||
|
||||
@ -37,7 +37,7 @@ test_terminal()
|
||||
|
||||
|
||||
## Quick start
|
||||
The following examples are supposed to be self-explaining. See [documentation](https://gcalderone.github.io/Gnuplot.jl/v1.2.0/) for further informations.
|
||||
The following examples are supposed to be self-explaining. See [documentation](https://gcalderone.github.io/Gnuplot.jl/v1.4.0/) for further informations.
|
||||
|
||||
### A simple parabola
|
||||
```julia
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Documenter, Gnuplot
|
||||
empty!(Gnuplot.options.mime)
|
||||
|
||||
makedocs(sitename="Gnuplot.jl",
|
||||
authors = "Giorgio Calderone",
|
||||
|
||||
@ -255,6 +255,70 @@ saveas("advanced014e") # hide
|
||||

|
||||
|
||||
|
||||
The [`contourlines()`](@ref) function also allows to calculate the contour lines encompassing a given fraction of the total counts of a 2D histogram. E.g. to plot the contours corresponding to 1, 2, and 3 $\sigma$ of a 2D Gaussian distribution:
|
||||
```@example abc
|
||||
x = randn(10^5);
|
||||
y = randn(10^5);
|
||||
h = hist(x, y, nbins1=20, nbins2=20);
|
||||
|
||||
# Calculate probability within 0 < r < σ
|
||||
p(σ) = round(1 - exp(-(σ^2) / 2), sigdigits=3)
|
||||
|
||||
# Draw contour lines at 1, 2 and 3 σ
|
||||
clines = contourlines(h, p.(1:3));
|
||||
@gp palette(:beach, smooth=true, rev=true) "set grid front" "set size ratio -1" h clines
|
||||
saveas("advanced014f") # hide
|
||||
```
|
||||

|
||||
|
||||
|
||||
## Interpolation of 2D scattered data
|
||||
The `dgrid3d()` function allows to interpolate 2D scattered data onto a 2D regular grid, e.g.:
|
||||
```@example abc
|
||||
x = (rand(200) .- 0.5) .* 3;
|
||||
y = (rand(200) .- 0.5) .* 3;
|
||||
z = exp.(-(x.^2 .+ y.^2));
|
||||
|
||||
# Interpolate on a 20x30 regular grid with splines
|
||||
gx, gy, gz = dgrid3d(x, y, z, "20,30 splines")
|
||||
|
||||
@gsp "set size ratio -1" "set xyplane at 0" xlab="X" ylab="Y" :-
|
||||
@gsp :- x y z "w p t 'Scattered data' lc pal"
|
||||
@gsp :- gx gy gz "w l t 'Interpolation on a grid' lc pal"
|
||||
saveas("advanced015a") # hide
|
||||
```
|
||||

|
||||
|
||||
|
||||
!!! warn
|
||||
The `splines` algorithm may be very slow on large datasets. An alternative option is to use a smoothing kernel, such as `gauss`.
|
||||
|
||||
|
||||
The interpolated data in scarcely sampled regions are poorly constrained, i.e. they are actually *extrapolated values*. By using the `extra=false` keyword all extrapolated values are set to `NaN`:
|
||||
|
||||
```@example abc
|
||||
x = randn(2000) .* 0.5;
|
||||
y = randn(2000) .* 0.5;
|
||||
rsq = x.^2 + y.^2;
|
||||
z = exp.(-rsq) .* sin.(y) .* cos.(2 * rsq);
|
||||
|
||||
@gsp "set size ratio -1" palette(:balance, smooth=true) "set view map" "set pm3d" :-
|
||||
@gsp :- "set multiplot layout 1,3" xr=[-2,2] yr=[-2,2] :-
|
||||
@gsp :- 1 tit="Scattered data" x y z "w p notit lc pal"
|
||||
|
||||
# Show extrapolated values
|
||||
gx, gy, gz = dgrid3d(x, y, z, "40,40 gauss 0.1,0.1")
|
||||
@gsp :- 2 tit="Interpolation on a grid\\n(extrapolated values are shown)" gx gy gz "w l notit lc pal"
|
||||
|
||||
# Hide exrapolated values
|
||||
gx, gy, gz = dgrid3d(x, y, z, "40,40 gauss 0.1,0.1", extra=false)
|
||||
@gsp :- 3 tit="Interpolation on a grid\\n(extrapolated values are hidden)" gx gy gz "w l notit lc pal"
|
||||
save(term="pngcairo size 1000,400 fontscale 1.0", output="assets/advanced015b.png") # hide
|
||||
```
|
||||

|
||||
|
||||
|
||||
|
||||
## Animations
|
||||
|
||||
The [Multiplot](@ref) capabilities can also be used to stack plots one above the other in order to create an animation, as in the following example:
|
||||
|
||||
@ -13,6 +13,7 @@ The list of **Gnuplot.jl** exported symbols is as follows:
|
||||
boxxy
|
||||
contourlines
|
||||
dataset_names
|
||||
dgrid3d
|
||||
gpexec
|
||||
gpmargins
|
||||
gpranges
|
||||
@ -20,6 +21,7 @@ gpvars
|
||||
hist
|
||||
linetypes
|
||||
palette
|
||||
palette_levels
|
||||
palette_names
|
||||
recipe
|
||||
save
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 38 KiB |
@ -21,7 +21,7 @@ saveas("basic000") # hide
|
||||
```
|
||||

|
||||
|
||||
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.
|
||||
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 [Display options](@ref) for further informations.
|
||||
|
||||
|
||||
Both the [`@gp`](@ref) and [`@gsp`](@ref) macros accept any number of arguments, whose meaning is interpreted as follows:
|
||||
@ -210,6 +210,16 @@ saveas("basic008a") # hide
|
||||
```
|
||||

|
||||
|
||||
The palette levels may be easily stretched by using the [`palette_levels()`](@ref) and modifying the numeric levels, e.g.:
|
||||
```@example abc
|
||||
x = 0:0.1:10pi
|
||||
v, l, n = palette_levels(:viridis)
|
||||
@gsp palette(v.^0.25, l, n) cbr=[-1,1].*30 :-
|
||||
@gsp :- x x.*sin.(x) x.*cos.(x) x./20 "w p pt 7 ps var lc pal"
|
||||
saveas("basic008b") # hide
|
||||
```
|
||||

|
||||
|
||||
The list of all available palette can be retrieved with [`palette_names()`](@ref):
|
||||
```@repl abc
|
||||
palette_names()
|
||||
|
||||
@ -21,6 +21,8 @@ The **Gnuplot.jl** package allows easy and fast use of [gnuplot](http://gnuplot.
|
||||
|
||||
- enhanced support for contour plots;
|
||||
|
||||
- 2D interpolation of scattered data on a regular grid;
|
||||
|
||||
- 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;
|
||||
|
||||
@ -19,11 +19,11 @@ Check **Gnuplot.jl** version with:
|
||||
```julia-repl
|
||||
julia> ]st Gnuplot
|
||||
Status `~/.julia/environments/v1.4/Project.toml`
|
||||
[dc211083] Gnuplot v1.2.0
|
||||
[dc211083] Gnuplot v1.4.1
|
||||
```
|
||||
If the displayed version is not `v1.2.0` you are probably having a dependency conflict. In this case try forcing installation of the latest version with:
|
||||
If the displayed version is not `v1.4.1` you are probably having a dependency conflict. In this case try forcing installation of the latest version with:
|
||||
```julia-repl
|
||||
julia> ]add Gnuplot@1.2.0
|
||||
julia> ]add Gnuplot@1.4.1
|
||||
```
|
||||
and check which package is causing the conflict.
|
||||
|
||||
|
||||
@ -9,6 +9,19 @@ push!( Gnuplot.options.init, linetypes(:Set1_5, lw=1.5, ps=1.5))
|
||||
saveas(file) = save(term="pngcairo size 550,350 fontscale 0.8", output="assets/$(file).png")
|
||||
```
|
||||
|
||||
# Display options
|
||||
|
||||
The display behaviour of **Gnuplot.jl** depends on the value of the `Gnuplot.options.gpviewer` flag:
|
||||
|
||||
- if `true` the plot is displayed in a gnuplot window, using one of the interactive terminals such as `wxt`, `qt` or `aqua`. This is the default setting when running a Julia REPL session; The terminal options can be customized using `Gnuplot.options.term`;
|
||||
|
||||
- if `false` the plot is displayed through the Julia [multimedia interface](https://docs.julialang.org/en/v1/base/io-network/#Multimedia-I/O-1), i.e. it is exported as either a `png`, `svg` or `html` file, and displayed in an external viewer. This is the default setting when running a Jupyter, JupyterLab or Juno session. The terminal options can be customized using the `Gnuplot.options.mime` dictionary.
|
||||
|
||||
The `Gnuplot.options.gpviewer` flag is automatically set when the package is first loaded according to the runtime environment, however the user can change its value at any time to fit specific needs. Further informations and examples for both options are available in this Jupyter [notebook](https://github.com/gcalderone/Gnuplot.jl/blob/gh-pages/v1.3.0/options/display.ipynb).
|
||||
|
||||
|
||||
|
||||
|
||||
# Package options and initialization
|
||||
|
||||
## Options
|
||||
@ -18,14 +31,21 @@ The package options are stored in a global structure available in Julia as `Gnup
|
||||
|
||||
- `cmd::String`: command to start the gnuplot process, default value is `"gnuplot"`. Use this field to specify a custom path to the gnuplot executable;
|
||||
|
||||
- `gpviewer::Bool`: use a gnuplot terminal as main plotting device (if `true`) or an external viewer (if `false`);
|
||||
|
||||
- `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
|
||||
Gnuplot.options.term = "wxt size 700,400";
|
||||
```
|
||||
|
||||
- `term_svg::String`: terminal to save png files (default: `"svg background rgb 'white' dynamic"`);
|
||||
- `mime::Dict{MIME, String}`: dictionary of MIME types and corresponding gnuplot terminals. Used to export images with either [`save()`](@ref) or `show()` (see [Display options](@ref)). Default values are:
|
||||
- `MIME"application/pdf" => "pdfcairo enhanced"`
|
||||
- `MIME"image/jpeg" => "jpeg enhanced"`
|
||||
- `MIME"image/png" => "pngcairo enhanced"`
|
||||
- `MIME"image/svg+xml" => "svg enhanced mouse standalone dynamic background rgb 'white'"`
|
||||
- `MIME"text/html" => "svg enhanced mouse standalone dynamic"`
|
||||
- `MIME"text/plain" => "dumb enhanced ansi"`
|
||||
|
||||
- `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
|
||||
@ -48,46 +68,47 @@ 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`;
|
||||
|
||||
|
||||
## Jupyter and Juno
|
||||
|
||||
**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
|
||||
|
||||
If you use **Gnuplot.jl** frequently you may find convenient to collect all the package settings ([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 automatically apply the package settings ([Options](@ref)) whenever the package is loaded. A possibility is to use [Requires.jl](https://github.com/JuliaPackaging/Requires.jl) and put the following code in the `~/.julia/config/startup.jl` initialization file (further info [here](https://docs.julialang.org/en/v1/stdlib/REPL/)):
|
||||
```julia
|
||||
macro gnuplotrc()
|
||||
return :(
|
||||
using Revise, Gnuplot;
|
||||
|
||||
# Uncomment following to true if you don't have the gnuplot
|
||||
using Requires
|
||||
@require Gnuplot="dc211083-a33a-5b79-959f-2ff34033469d" begin
|
||||
@info "Custom Gnuplot initialization"
|
||||
# Uncomment the following if you don't have the gnuplot
|
||||
# executable installed on your platform:
|
||||
#Gnuplot.options.dry = true;
|
||||
|
||||
# Uncomment the following and set the proper path if the
|
||||
# gnuplot executable is not available in your $PATH
|
||||
# Set the proper path if the gnuplot executable is not
|
||||
# available in your $PATH
|
||||
#Gnuplot.options.cmd = "/path/to/gnuplot";
|
||||
|
||||
# Force a specific display behaviour (see documentation). If
|
||||
# not given explicit Gnuplot.jl will choose the best option
|
||||
# according to your runtime environment.
|
||||
#Gnuplot.options.gpviewer = true
|
||||
|
||||
# Set the default terminal for interacitve use
|
||||
Gnuplot.options.term = "wxt size 700,400";
|
||||
|
||||
# Set the terminal options for the exported MIME types:
|
||||
#Gnuplot.options.mime[MIME"image/png"] = "";
|
||||
#Gnuplot.options.mime[MIME"image/svg+xml"] = "svg enhanced standalone dynamic";
|
||||
#Gnuplot.options.mime[MIME"text/html"] = "svg enhanced standalone mouse dynamic";
|
||||
|
||||
# Set the terminal to plot in a terminal emulator:
|
||||
# (try with `save(MIME"text/plain")`):
|
||||
#Gnuplot.options.mime[MIME"text/plain"] = "sixelgd enhanced"; # requires vt340 emulation
|
||||
|
||||
# Set the default linetypes
|
||||
empty!(Gnuplot.options.init);
|
||||
push!(Gnuplot.options.init, linetypes(:Set1_5, lw=1.5, ps=1.5));
|
||||
push!(Gnuplot.options.init, Gnuplot.linetypes(:Set1_5, lw=1.5, ps=1.5));
|
||||
|
||||
# Initialize the gnuplot REPL using the provided `start_key`.
|
||||
# Comment the following to disable the REPL.
|
||||
Gnuplot.repl_init(start_key='>');
|
||||
)
|
||||
if Gnuplot.options.gpviewer;
|
||||
Gnuplot.repl_init(start_key='>');
|
||||
end;
|
||||
end
|
||||
```
|
||||
At the Julia prompt you may load the package and the associated settings by typing:
|
||||
```julia
|
||||
julia> @gnuplotrc
|
||||
```
|
||||
and you're ready to go.
|
||||
|
||||
The above code will be automatically when you first load the package with `using Gnuplot`.
|
||||
|
||||
@ -125,7 +125,7 @@ end
|
||||
with only one mandatory argument. In order to exploit the optional keyword we can explicitly invoke the recipe as follows:
|
||||
```@example abc
|
||||
img = testimage("walkbridge");
|
||||
@gp palette(:gray) recipe(img, "flipy rot=15deg")
|
||||
@gp palette(:gray1) recipe(img, "flipy rot=15deg")
|
||||
saveas("recipes007c") # hide
|
||||
```
|
||||

|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# Style Guide
|
||||
|
||||
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.
|
||||
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 a reduced code readability if not used judiciously.
|
||||
|
||||
Here I will summarize a few, non-mandatory, guidelines which allows to maintain a neat syntax and a high readability:
|
||||
|
||||
|
||||
@ -4,11 +4,7 @@ Gnuplot provides dozens of terminals to display plots or export them into files
|
||||
|
||||
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
|
||||
Gnuplot.options.term = "wxt")
|
||||
```
|
||||
or directly send the command to a specific session (see [Direct command execution](@ref))
|
||||
```julia
|
||||
gpexec("set term wxt")
|
||||
Gnuplot.options.term = "wxt"
|
||||
```
|
||||
See official [gnuplot documentation](http://gnuplot.sourceforge.net/documentation.html) for further info on terminals and their options.
|
||||
|
||||
@ -16,13 +12,13 @@ See official [gnuplot documentation](http://gnuplot.sourceforge.net/documentatio
|
||||
## 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:
|
||||
You may use such terminals with:
|
||||
```
|
||||
"set term wxt size 800,600"
|
||||
Gnuplot.options.term = "wxt size 800,600"
|
||||
```
|
||||
or
|
||||
```
|
||||
"set term qt size 800,600"
|
||||
Gnuplot.options.term = "qt size 800,600"
|
||||
```
|
||||
(the `size 800,600` is optional and can be omitted).
|
||||
|
||||
@ -30,9 +26,35 @@ 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`)
|
||||
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.
|
||||
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. 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`).
|
||||
|
||||
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:
|
||||
Dumb terminal can be used as follows:
|
||||
|
||||
```jldoctest; setup = :(using Gnuplot)
|
||||
julia> origterm = Gnuplot.options.term;
|
||||
|
||||
julia> Gnuplot.options.term = "dumb size 60,15";
|
||||
|
||||
julia> @gp "plot sin(x)"
|
||||
|
||||
1 +-------------------------------------------------+
|
||||
0.8 |-+ *+ * + ** ** + * * +-|
|
||||
0.6 |-+ * ** * * sin(x) *******-|
|
||||
0.4 |*+ * * * * * *+-|
|
||||
0.2 |*+ * * * * * *-|
|
||||
0 |*+ * * * * * *-|
|
||||
| * * * * * * *|
|
||||
-0.2 |-* * * * * * +*|
|
||||
-0.4 |-+* * * * * * +*|
|
||||
-0.6 |-+* * * * ** * +-|
|
||||
-0.8 |-+ * * + ** ** + * * +-|
|
||||
-1 +-------------------------------------------------+
|
||||
-10 -5 0 5 10
|
||||
|
||||
julia> Gnuplot.options.term = origterm;
|
||||
|
||||
```
|
||||
A sixel plot on `xterm` looks as follows:
|
||||

|
||||
|
||||
The above terminals are available if gnuplot has been compiled with the `--with-bitmap-terminals` option enabled and Libgd (only for `sixelgd`).
|
||||
@ -41,7 +63,7 @@ The above terminals are available if gnuplot has been compiled with the `--with-
|
||||
## Export to image files
|
||||
|
||||
Gnuplot provides dozens of terminals able to export on files. Examples are:
|
||||
- `cairopng` to export PNG files;
|
||||
- `pngcairo` to export PNG files;
|
||||
- `pdfcairo` for PDF;
|
||||
- `jpeg` for JPG;
|
||||
- `gif` for GIF (see [Animations](@ref)).
|
||||
@ -58,7 +80,7 @@ Gnuplot is also able to export vector (i.e. non-raster) plots through the `svg`
|
||||
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 tit="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*}""" *
|
||||
@ -74,7 +96,7 @@ approx = fill(0., length(x));
|
||||
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.
|
||||
If you add a path in the `output=` keyword this will also be copied in the the `.tex` file, and may generate errors when compiling ``\LaTeX`` code. The simplest way to solve this problem is to use just filenames, with no paths.
|
||||
|
||||
The two output files (`test.tex` and `test.pdf`) can then be included in a ``\LaTeX`` file as follows:
|
||||
```latex
|
||||
|
||||
712
src/Gnuplot.jl
712
src/Gnuplot.jl
File diff suppressed because it is too large
Load Diff
@ -29,7 +29,12 @@ recipe(h::Histogram2D) =
|
||||
|
||||
Implicit recipes to visualize iso-contour lines.
|
||||
"""
|
||||
recipe(c::IsoContourLines) = PlotElement(data=c.data, plot="w l t '$(c.z)'")
|
||||
function recipe(c::IsoContourLines)
|
||||
if isnan(c.prob)
|
||||
return PlotElement(data=c.data, plot="w l t '$(c.z)'")
|
||||
end
|
||||
return PlotElement(data=c.data, plot="w l t '$(round(c.prob * 100, sigdigits=6))%'")
|
||||
end
|
||||
recipe(v::Vector{IsoContourLines}) = recipe.(v)
|
||||
|
||||
|
||||
|
||||
@ -1,16 +1,15 @@
|
||||
using Test, Gnuplot
|
||||
try
|
||||
@info "Gnuplot version: " * string(Gnuplot.gpversion())
|
||||
@info "Gnuplot.jl version: " * string(Gnuplot.version())
|
||||
@info "gnuplot version: " * string(Gnuplot.gpversion())
|
||||
catch
|
||||
Gnuplot.options.dry = true
|
||||
end
|
||||
Gnuplot.options.term = "unknown"
|
||||
Gnuplot.options.gpviewer = true
|
||||
|
||||
x = [1, 2, 3]
|
||||
y = [4, 5, 6]
|
||||
|
||||
|
||||
|
||||
s = Gnuplot.arrays2datablock(x)
|
||||
@test all(s .== [" 1" ,
|
||||
" 2" ,
|
||||
@ -90,10 +89,30 @@ s = Gnuplot.arrays2datablock(1:3, 1:3, ["One", "Two", "Three"])
|
||||
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
dummy = palette_names()
|
||||
pal = palette(:deepsea)
|
||||
@test pal == "set palette defined (0.0 '#2B004D', 0.25 '#4E0F99', 0.5 '#3C54D4', 0.75 '#48A9F8', 1.0 '#C5ECFF')\nset palette maxcol 5\n"
|
||||
ls = linetypes(:Set1_5)
|
||||
@test ls == "unset for [i=1:256] linetype i\nset linetype 1 lc rgb '#E41A1C' lw 1 dt solid pt 1 ps 1\nset linetype 2 lc rgb '#377EB8' lw 1 dt solid pt 2 ps 1\nset linetype 3 lc rgb '#4DAF4A' lw 1 dt solid pt 3 ps 1\nset linetype 4 lc rgb '#984EA3' lw 1 dt solid pt 4 ps 1\nset linetype 5 lc rgb '#FF7F00' lw 1 dt solid pt 5 ps 1\nset linetype cycle 5\n"
|
||||
ls = linetypes(:Set1_5, lw=1.5, ps=2)
|
||||
@test ls == "unset for [i=1:256] linetype i\nset linetype 1 lc rgb '#E41A1C' lw 1.5 dt solid pt 1 ps 2\nset linetype 2 lc rgb '#377EB8' lw 1.5 dt solid pt 2 ps 2\nset linetype 3 lc rgb '#4DAF4A' lw 1.5 dt solid pt 3 ps 2\nset linetype 4 lc rgb '#984EA3' lw 1.5 dt solid pt 4 ps 2\nset linetype 5 lc rgb '#FF7F00' lw 1.5 dt solid pt 5 ps 2\nset linetype cycle 5\n"
|
||||
|
||||
dummy = terminals()
|
||||
# if "sixelgd" in terminals()
|
||||
# Gnuplot.options.term = "sixelgd enhanced"
|
||||
# elseif "sixel" in terminals()
|
||||
# Gnuplot.options.term = "sixel enhanced"
|
||||
# elseif "dumb" in terminals()
|
||||
# Gnuplot.options.term = "dumb"
|
||||
# else
|
||||
# Gnuplot.options.term = "unknown"
|
||||
# end
|
||||
# Gnuplot.quitall()
|
||||
|
||||
# Force unknown on Travis CI
|
||||
Gnuplot.options.term = "unknown"
|
||||
|
||||
@gp 1:9
|
||||
@info "using terminal: " terminal()
|
||||
#test_terminal("unknown")
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
# Test wth empty dataset
|
||||
@ -247,8 +266,19 @@ Gnuplot.quitall()
|
||||
"splot x9, v, (u<0.5) ? -1 : sinc(x9,v) notitle")
|
||||
|
||||
|
||||
|
||||
x = randn(5000);
|
||||
y = randn(5000);
|
||||
h = hist(x, y, nbins1=20, nbins2=20);
|
||||
clines = contourlines(h, "levels discrete 15, 30, 45");
|
||||
@gp clines
|
||||
@gp "set size ratio -1"
|
||||
for i in 1:length(clines)
|
||||
@gp :- clines[i].data "w l t '$(clines[i].z)' lw $i dt $i"
|
||||
end
|
||||
|
||||
|
||||
Gnuplot.options.verbose = true
|
||||
# Gnuplot.options.term = "sixel" not vailable in Travis CI
|
||||
@gp randn(10^6) randn(10^6)
|
||||
@gp :- 0. 0.
|
||||
Gnuplot.quit(:default)
|
||||
@ -256,6 +286,8 @@ Gnuplot.quit(:default)
|
||||
Gnuplot.options.dry = true
|
||||
@gp hist(randn(1000))
|
||||
|
||||
t = terminals()
|
||||
# Various hist() corner cases
|
||||
@gp hist([1,2,3], bs=2)
|
||||
@gp hist([1,1,1], bs=1)
|
||||
|
||||
Gnuplot.quitall()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user