From 59434a6021fc1ff0f6ed5517cfa3ffa942d624bb Mon Sep 17 00:00:00 2001 From: Giorgio Calderone Date: Wed, 8 Apr 2020 00:09:59 +0200 Subject: [PATCH] Minor changes --- Project.toml | 2 ++ docs/src/advanced.md | 11 +++++------ docs/src/basic.md | 7 +++++-- docs/src/index.md | 4 ++-- docs/src/style.md | 8 ++++---- src/Gnuplot.jl | 9 +++++---- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Project.toml b/Project.toml index 8ab031d..4f3d4e1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,9 +1,11 @@ name = "Gnuplot" uuid = "dc211083-a33a-5b79-959f-2ff34033469d" +version = "1.1.0" [deps] ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" StructC14N = "d2514e9c-36c4-5b8e-97e2-51e7675c221c" diff --git a/docs/src/advanced.md b/docs/src/advanced.md index 58d895d..b9c3f14 100644 --- a/docs/src/advanced.md +++ b/docs/src/advanced.md @@ -63,10 +63,10 @@ A named dataset is available until the session is reset, i.e. as long as `:-` is **Gnuplot.jl** can draw multiple plots in the same figure by exploiting the `multiplot` command. Each plot is identified by a positive integer number, which can be used as argument to `@gp` to redirect commands to the appropriate plot. -Continuing previous example we can plot both data and best fit model (in plot `1`) and residuals (in plot `2`): +Continuing with the previous example we can plot both data and best fit model (in plot `1`) and residuals (in plot `2`): ```@example abc @gp :- "set multiplot layout 2,1" -@gp :- 1 "p $name w errorbars t 'Data'" +@gp :- 1 "p $name w errorbars t 'Data'" @gp :- "p $name u 1:(f(\$1)) w l t 'Best fit model'" @gp :- 2 "p $name u 1:((f(\$1)-\$2) / \$3):(1) w errorbars t 'Resid. [{/Symbol s}]'" @gp :- [extrema(x)...] [0,0] "w l notit dt 2 lc rgb 'black'" # reference line @@ -79,7 +79,7 @@ Note that the order of the plots is not relevant, i.e. we would get the same res @gp :- "set multiplot layout 2,1" @gp :- 2 "p $name u 1:((f(\$1)-\$2) / \$3):(1) w errorbars t 'Resid. [{/Symbol s}]'" @gp :- [extrema(x)...] [0,0] "w l notit dt 2 lc rgb 'black'" # reference line -@gp :- 1 "p $name w errorbars t 'Data'" +@gp :- 1 "p $name w errorbars t 'Data'" @gp :- "p $name u 1:(f(\$1)) w l t 'Best fit model'" ``` @@ -181,7 +181,7 @@ saveas("ex014c") # hide ## Contour lines -Although gnuplot already handles contours by itself (with the `set contour` command), **Gnuplot.jl** provides a way to calculate contour lines paths before displaying them, using the [`contourlines()`](@ref) function. We may use it for, e.g., plot contour lines with customized widths and palette, according to their z level. Continuing previous example: +Although gnuplot already handles contours by itself (with the `set contour` command), **Gnuplot.jl** provides a way to calculate contour lines paths before displaying them, using the [`contourlines()`](@ref) function. We may use it for, e.g., plot contour lines with customized widths and palette, according to their z level. Continuing with the previous example: ```@example abc clines = contourlines(h.bins1, h.bins2, h.counts, cntrparam="levels discrete 10, 30, 60, 90"); for i in 1:length(clines) @@ -200,7 +200,7 @@ The [Multiplot](@ref) capabilities can also be used to stack plots one above the x = y = -10:0.33:10 fz(x,y) = sin.(sqrt.(x.^2 + y.^2))./sqrt.(x.^2+y.^2) fxy = [fz(x,y) for x in x, y in y] -@gsp "set xyplane at 0" "unset colorbox" cb=[-1,1] zr=[-1,1] +@gsp "set xyplane at 0" "unset colorbox" cbr=[-1,1] zr=[-1,1] frame = 0 for direction in [-1,1] for factor in -1:0.1:1 @@ -278,4 +278,3 @@ gpexec("set term unknown") - `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. - diff --git a/docs/src/basic.md b/docs/src/basic.md index 1316ac2..fd559ec 100644 --- a/docs/src/basic.md +++ b/docs/src/basic.md @@ -68,6 +68,8 @@ saveas("ex002") # hide saveas("ex003") # hide ``` ![](assets/ex003.png) +!!! note + The trailing `:-` symbol means the plot will not be updated until the last statement. ### Send data from Julia to gnuplot: @@ -117,6 +119,7 @@ In order to avoid typing long, and very frequently used gnuplot commands, **Gnup - `xlabel="..."` => `"set xlabel \"...\""`; - `ylabel="..."` => `"set ylabel \"...\""`; - `zlabel="..."` => `"set zlabel \"...\""`; + - `cblabel="..."` => `"set cblabel \"...\""`; - `xlog=true` => `set logscale x`; - `ylog=true` => `set logscale y`; - `zlog=true` => `set logscale z`; @@ -162,7 +165,7 @@ 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" +@gp palette(:viridis) "set size square" "set autoscale fix" img "rotate=-0.5pi with image notit" saveas("ex007c") # hide ``` ![](assets/ex007c.png) @@ -233,7 +236,7 @@ Note that you can pass both the terminal name and its options via the `term=` ke ## Gnuplot scripts 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. -To generate a script for one of the example above use: +To generate a script for one of the examples above use: ```julia save("script.gp") ``` diff --git a/docs/src/index.md b/docs/src/index.md index ea81c23..ca99849 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -41,7 +41,7 @@ A powerful plotting framework is among the most important tool in the toolbox of Unlike other packages **Gnuplot.jl** is not a pure Julia solution as it depends on an external package to actually generate plots. However, if gnuplot is not available on a given platform, the package could still be used in "*dry*" mode, and no error for a missing dependency will be raised (see [Dry sessions](@ref)). -The **Gnuplot.jl** package development follows a minimalistic approach: it is essentially a thin layer to send data and commands to gnuplot. This way all underlying capabilities, both present and future ones, are automatically exposed to Julia user, with no need to implement dedicated wrappers. +The **Gnuplot.jl** package development follows a minimalistic approach: it is essentially a thin layer to send data and commands to gnuplot. This way all underlying capabilities, both present and future ones, are automatically exposed to the Julia user, with no need to implement dedicated wrappers. The functionalities 1, 2 and 3 listed above are similar to those provided by the [Gaston](https://github.com/mbaz/Gaston.jl) package. **Gnuplot.jl** also provides features 4 and 5, as well as the minimalistic approach. @@ -52,7 +52,7 @@ Any modern plotting package is able to produce a simple scatter plot, with custo **Gnuplot.jl** aims to be ready for even the most challenging plots by relying on the widely and long lasting used gnuplot application, and by allowing each native feature (both present and future ones) to be immediately available in the Julia language. Moreover, **Gnuplot.jl** provides a unique syntax specifically aimed to increase productivity while performing interactive data exploration. -Last but not least, have a look at the **Gnuplot.jl** [Examples](#ref) page. +Last but not least, have a look at the **Gnuplot.jl** [Examples](@ref) page. ## Notation diff --git a/docs/src/style.md b/docs/src/style.md index b2b552a..f14686f 100644 --- a/docs/src/style.md +++ b/docs/src/style.md @@ -9,14 +9,14 @@ The two most important symbols exported by the package (`@gp` and `@gsp`) are ma ```julia @gp x y "with lines" ``` -in place of +in place of ```julia @gp(x, y, "with lines") ``` 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: ```julia -@gp "set grid" :- +@gp "set grid" :- @gp :- x y "with lines" ``` Note that the trailing `:-` symbol is not mandatory. If omitted, the plot will be updated at each statement (rather than at the last one). @@ -28,7 +28,7 @@ As discussed in [Keywords for common commands](@ref) several commonly used gnupl ```julia @gp ... xrange=[-1,5] ... ``` -in place of +in place of ```julia @gp ... "set xrange [-1:5]" ... ``` @@ -60,7 +60,7 @@ Moreover, in many gnuplot examples and documentation it is very common to use ab The two following examples produce exactly the same plot: ```julia x = -10.:10 -@gp "set grid" "set multiplot layout 2,1" +@gp "set grid" "set multiplot layout 2,1" @gp :- 1 x x.^2 "w l t 'f(x) = x^2" # first plot @gp :- 2 x x.^3 "w l t 'f(x) = x^3" # second plot ``` diff --git a/src/Gnuplot.jl b/src/Gnuplot.jl index a52acb7..83c9092 100644 --- a/src/Gnuplot.jl +++ b/src/Gnuplot.jl @@ -1,6 +1,6 @@ module Gnuplot -using StatsBase, ColorSchemes, ColorTypes, StructC14N, DataStructures +using StatsBase, ColorSchemes, ColorTypes, Colors, StructC14N, DataStructures import Base.reset import Base.write @@ -1037,7 +1037,7 @@ end Return the **Gnuplot.jl** package version. """ -version() = v"1.0-dev" +version() = v"1.1.0" # --------------------------------------------------------------------- """ @@ -1150,6 +1150,7 @@ The `@gp` macro, and its companion `@gsp` for 3D plots, allows to send data and - `xlabel="..."` => `"set xlabel \"...\""`; - `ylabel="..."` => `"set ylabel \"...\""`; - `zlabel="..."` => `"set zlabel \"...\""`; + - `cblabel="..."` => `"set cblabel \"...\""`; - `xlog=true` => `set logscale x`; - `ylog=true` => `set logscale y`; - `zlog=true` => `set logscale z`. @@ -1305,7 +1306,7 @@ function linetypes(cmap::ColorScheme; rev=false) else color = cmap.colors[i] end - push!(out, "set linetype $i lc rgb '#" * Base.hex(color)) + push!(out, "set linetype $i lc rgb '#" * Colors.hex(color)) end return join(out, "\n") * "\nset linetype cycle " * string(length(cmap.colors)) * "\n" end @@ -1328,7 +1329,7 @@ function palette(cmap::ColorScheme; rev=false) else color = get(cmap, x) end - push!(levels, "$x '#" * Base.hex(color) * "'") + push!(levels, "$x '#" * Colors.hex(color) * "'") end return "set palette defined (" * join(levels, ", ") * ")\nset palette maxcol $(length(cmap.colors))\n" end