diff --git a/docs/src/examples/coordinates.md b/docs/src/examples/coordinates.md index 4bc0cbca..942003af 100644 --- a/docs/src/examples/coordinates.md +++ b/docs/src/examples/coordinates.md @@ -1,19 +1,11 @@ # Coordinates -```jl -import PGFPlotsX -const pgf = PGFPlotsX -using LaTeXStrings -``` - ```@setup pgf -import PGFPlotsX -const pgf = PGFPlotsX -using LaTeXStrings +using PGFPlotsX savefigs = (figname, obj) -> begin - pgf.save(figname * ".pdf", obj) + PGFPlotsX.save(figname * ".pdf", obj) run(`pdf2svg $(figname * ".pdf") $(figname * ".svg")`) - pgf.save(figname * ".tex", obj); + PGFPlotsX.save(figname * ".tex", obj); return nothing end ``` @@ -24,16 +16,16 @@ For basic usage, consider `AbstractVectors` and iterables. Notice how non-finite ```@example pgf x = linspace(-1, 1, 51) # so that it contains 1/0 -pgf.@pgf pgf.Axis( +@pgf Axis( { xmajorgrids, ymajorgrids, }, - pgf.Plot( + Plot( { no_marks, }, - pgf.Coordinates(x, 1 ./ x) + Coordinates(x, 1 ./ x) ) ) savefigs("coordinates-simple", ans) # hide @@ -46,13 +38,13 @@ savefigs("coordinates-simple", ans) # hide Use `xerror`, `xerrorplus`, `xerrorminus`, `yerror` etc for error bars. ```@example pgf x = linspace(0, 2π, 20) -pgf.@pgf pgf.Plot( +@pgf Plot( { "no marks", "error bars/y dir=both", "error bars/y explicit", }, - pgf.Coordinates(x, sin.(x); yerror = 0.2*cos.(x)) + Coordinates(x, sin.(x); yerror = 0.2*cos.(x)) ) savefigs("coordinates-errorbars", ans) # hide ``` @@ -65,11 +57,11 @@ Use three vectors to construct 3D coordinates. ```@example pgf t = linspace(0, 6*π, 100) -pgf.@pgf pgf.Plot3( +@pgf Plot3( { no_marks, }, - pgf.Coordinates(t .* sin.(t), t .* cos.(t), .-t) + Coordinates(t .* sin.(t), t .* cos.(t), .-t) ) savefigs("coordinates-3d", ans) # hide ``` @@ -84,11 +76,11 @@ A convenience constructor is available for plotting a matrix of values calculate x = linspace(-2, 2, 20) y = linspace(-0.5, 3, 25) f(x, y) = (1 - x)^2 + 100*(y - x^2)^2 -pgf.@pgf pgf.Plot3( +@pgf Plot3( { surf, }, - pgf.Coordinates(x, y, f.(x, y')); + Coordinates(x, y, f.(x, y')); incremental = false ) savefigs("coordinates-3d-matrix", ans) # hide @@ -101,18 +93,18 @@ savefigs("coordinates-3d-matrix", ans) # hide ```@example pgf x = linspace(-2, 2, 40) y = linspace(-0.5, 3, 50) -pgf.@pgf pgf.Axis( +@pgf Axis( { view = (0, 90), colorbar, "colormap/jet", }, - pgf.Plot3( + Plot3( { surf, shader = "flat", }, - pgf.Coordinates(x, y, @. √(f(x, y'))); + Coordinates(x, y, @. √(f(x, y'))); incremental = false ) ) diff --git a/docs/src/examples/gallery.md b/docs/src/examples/gallery.md index 603bf179..7243c71c 100644 --- a/docs/src/examples/gallery.md +++ b/docs/src/examples/gallery.md @@ -1,22 +1,14 @@ # PGFPlots manual gallery Examples converted from [the PGFPlots manual gallery](http://pgfplots.sourceforge.net/gallery.html). -This is a work in progress. All the examples are run with the following code added to them. - -```jl -import PGFPlotsX -const pgf = PGFPlotsX -using LaTeXStrings -``` +This is a work in progress. ```@setup pgf -import PGFPlotsX -const pgf = PGFPlotsX -using LaTeXStrings +using PGFPlotsX savefigs = (figname, obj) -> begin - pgf.save(figname * ".pdf", obj) + PGFPlotsX.save(figname * ".pdf", obj) run(`pdf2svg $(figname * ".pdf") $(figname * ".svg")`) - pgf.save(figname * ".tex", obj); + PGFPlotsX.save(figname * ".tex", obj); return nothing end ``` @@ -25,17 +17,17 @@ end ```@example pgf -pgf.@pgf pgf.Axis( +@pgf Axis( { xlabel = "Cost", ylabel = "Error", }, - pgf.Plot( + Plot( { color = "red", mark = "x" }, - pgf.Coordinates( + Coordinates( [ (2, -2.8559703), (3, -3.5301677), @@ -58,13 +50,14 @@ savefigs("cost-error", ans) # hide ------------------------ ```@example pgf -pgf.@pgf pgf.Axis( +using LaTeXStrings +@pgf Axis( { xlabel = L"x", ylabel = L"f(x) = x^2 - x + 4" }, - pgf.Plot( - pgf.Expression("x^2 - x + 4") + Plot( + Expression("x^2 - x + 4") ) ) savefigs("simple-expression", ans) # hide @@ -77,15 +70,15 @@ savefigs("simple-expression", ans) # hide ------------------------ ```@example pgf -pgf.@pgf pgf.Axis( +@pgf Axis( { height = "9cm", width = "9cm", grid = "major", }, [ - pgf.Plot(pgf.Expression("-x^5 - 242"); label = "model") - pgf.Plot(pgf.Coordinates( + Plot(Expression("-x^5 - 242"); label = "model") + Plot(Coordinates( [ (-4.77778,2027.60977), (-3.55556,347.84069), @@ -110,19 +103,19 @@ savefigs("cost-gain", ans) # hide ------------------------ ```@example pgf -pgf.@pgf pgf.Axis( +@pgf Axis( { xlabel = "Cost", ylabel = "Gain", xmode = "log", ymode = "log", }, - pgf.Plot( + Plot( { color = "red", mark = "x" }, - pgf.Coordinates( + Coordinates( [ (10, 100), (20, 150), @@ -145,18 +138,18 @@ savefigs("cost-gain-log-log", ans) # hide ------------------------ ```@example pgf -pgf.@pgf pgf.Axis( +@pgf Axis( { xlabel = "Cost", ylabel = "Gain", ymode = "log", }, - pgf.Plot( + Plot( { color = "blue", mark = "*" }, - pgf.Coordinates( + Coordinates( [ (1, 8) (2, 16) @@ -180,7 +173,8 @@ savefigs("cost-gain-ylog", ans) # hide ------------------------ ```@example pgf -pgf.@pgf pgf.Axis( +using LaTeXStrings +@pgf Axis( { xlabel = "Degrees of freedom", ylabel = L"$L_2$ Error", @@ -188,31 +182,31 @@ pgf.@pgf pgf.Axis( ymode = "log", }, [ - pgf.Plot(pgf.Coordinates( + Plot(Coordinates( [( 5, 8.312e-02), ( 17, 2.547e-02), ( 49, 7.407e-03), ( 129, 2.102e-03), ( 321, 5.874e-04), ( 769, 1.623e-04), (1793, 4.442e-05), (4097, 1.207e-05), (9217, 3.261e-06),] )), - pgf.Plot(pgf.Coordinates( + Plot(Coordinates( [( 7, 8.472e-02), ( 31, 3.044e-02), (111, 1.022e-02), ( 351, 3.303e-03), ( 1023, 1.039e-03), (2815, 3.196e-04), (7423, 9.658e-05), (18943, 2.873e-05), (47103, 8.437e-06),] )), - pgf.Plot(pgf.Coordinates( + Plot(Coordinates( [( 9, 7.881e-02), ( 49, 3.243e-02), ( 209, 1.232e-02), ( 769, 4.454e-03), ( 2561, 1.551e-03), ( 7937, 5.236e-04), (23297, 1.723e-04), (65537, 5.545e-05), (178177, 1.751e-05),] )), - pgf.Plot(pgf.Coordinates( + Plot(Coordinates( [( 11, 6.887e-02), ( 71, 3.177e-02), ( 351, 1.341e-02), ( 1471, 5.334e-03), ( 5503, 2.027e-03), ( 18943, 7.415e-04), (61183, 2.628e-04), (187903, 9.063e-05), (553983, 3.053e-05),] )), - pgf.Plot(pgf.Coordinates( + Plot(Coordinates( [( 13, 5.755e-02), ( 97, 2.925e-02), ( 545, 1.351e-02), ( 2561, 5.842e-03), ( 10625, 2.397e-03), ( 40193, 9.414e-04), (141569, 3.564e-04), (471041, 1.308e-04), (1496065, 4.670e-05),] @@ -229,7 +223,7 @@ savefigs("dof-error", ans) # hide ------------------------ ```@example pgf -pgf.@pgf pgf.Axis( +@pgf Axis( { "scatter/classes" = { a = {mark = "square*", "blue"}, @@ -237,13 +231,13 @@ pgf.@pgf pgf.Axis( c = {mark = "o", draw = "black"}, } }, - pgf.Plot( + Plot( { scatter, "only marks", "scatter src" = "explicit symbolic", }, - pgf.Table( + Table( { meta = "label" }, @@ -263,19 +257,19 @@ savefigs("table-label", ans) # hide ------------------------ ```@example pgf -pgf.@pgf pgf.Axis( +@pgf Axis( { "nodes near coords" = raw"(\coordindex)", title = raw"\texttt{patch type=quadratic spline}", }, - pgf.Plot( + Plot( { mark = "*", patch, mesh, # without mesh, pgfplots tries to fill, # "patch type" = "quadratic spline", <- Should work?? }, - pgf.Coordinates( + Coordinates( [ # left, right, middle-> first segment (0, 0), (1, 1), (0.5, 0.5^2), @@ -295,14 +289,14 @@ savefigs("spline-quadratic", ans) # hide ------------------------ ```@example pgf -pgf.@pgf pgf.Plot3( +@pgf Plot3( { mesh, scatter, samples = 10, domain = 0:1 }, - pgf.Expression("x * (1-x) * y * (1-y)") + Expression("x * (1-x) * y * (1-y)") ) savefigs("mesh-scatter", ans) # hide ``` diff --git a/docs/src/examples/juliatypes.md b/docs/src/examples/juliatypes.md index 2c1451cf..7987f1ac 100644 --- a/docs/src/examples/juliatypes.md +++ b/docs/src/examples/juliatypes.md @@ -1,22 +1,13 @@ # Julia types There is some support to directly use Julia objects from different popular packages in PGFPlotsX.jl. Examples of these are given here. -All code is assumed to include the following: - -```jl -import PGFPlotsX -const pgf = PGFPlotsX -using LaTeXStrings -``` ```@setup pgf -import PGFPlotsX -const pgf = PGFPlotsX -using LaTeXStrings +using PGFPlotsX savefigs = (figname, obj) -> begin - pgf.save(figname * ".pdf", obj) + PGFPlotsX.save(figname * ".pdf", obj) run(`pdf2svg $(figname * ".pdf") $(figname * ".svg")`) - pgf.save(figname * ".tex", obj); + PGFPlotsX.save(figname * ".tex", obj); return nothing end ``` @@ -30,10 +21,10 @@ using Colors μ = 0 σ = 1e-3 -axis = pgf.Axis() -pgf.@pgf for (i, col) in enumerate(distinguishable_colors(10)) +axis = Axis() +@pgf for (i, col) in enumerate(distinguishable_colors(10)) offset = i * 50 - p = pgf.Plot(pgf.Expression("exp(-(x-$μ)^2 / (2 * $σ^2)) / ($σ * sqrt(2*pi)) + $offset"), + p = Plot(Expression("exp(-(x-$μ)^2 / (2 * $σ^2)) / ($σ * sqrt(2*pi)) + $offset"), { color = col, domain = "-3*$σ:3*$σ", @@ -54,9 +45,9 @@ Using a colormap ```@example pgf using Colors -pgf.@pgf begin -p = pgf.Plot3( - pgf.Expression("cos(deg(x)) * sin(deg(y))"), +@pgf begin +p = Plot3( + Expression("cos(deg(x)) * sin(deg(y))"), { surf, point_meta = "y", @@ -65,14 +56,14 @@ p = pgf.Plot3( incremental = false ) colormaps = ["Blues", "Greens", "Oranges", "Purples"] -td = pgf.TikzDocument() +td = TikzDocument() for cmap in colormaps - pgf.push_preamble!(td, (cmap, Colors.colormap(cmap))) + push_preamble!(td, (cmap, Colors.colormap(cmap))) end -tp = pgf.TikzPicture("scale" => 0.5) +tp = TikzPicture("scale" => 0.5) push!(td, tp) -gp = pgf.GroupPlot({ group_style = {group_size = "2 by 2"}}) +gp = GroupPlot({ group_style = {group_size = "2 by 2"}}) push!(tp, gp) for cmap in colormaps @@ -95,13 +86,13 @@ Creating a `Table` from a `DataFrame` will write it as expected. using RDatasets df = dataset("datasets", "iris") # load the dataset -pgf.@pgf pgf.Axis( +@pgf Axis( { legend_pos = "south east", xlabel = "Sepal length", ylabel = "Sepal width", }, - [pgf.Plot( + [Plot( { scatter, "only marks", @@ -113,7 +104,7 @@ pgf.@pgf pgf.Axis( virginica = {mark = "o", "black"}, } }, - pgf.Table( + Table( { x = "SepalLength", y = "SepalWidth", @@ -121,7 +112,7 @@ pgf.@pgf pgf.Axis( df, # <--- Creating a Table from a DataFrame ) ), - pgf.Legend(["Setosa", "Versicolor", "Virginica"]) + Legend(["Setosa", "Versicolor", "Virginica"]) ] ) savefigs("dataframes", ans) # hide @@ -141,11 +132,11 @@ using Contour x = 0.0:0.1:2π y = 0.0:0.1:2π f = (x,y) -> sin(x)*sin(y) -pgf.@pgf pgf.Plot({ +@pgf Plot({ contour_prepared, very_thick }, - pgf.Table(contours(x, y, f.(x, y'), 6)); + Table(contours(x, y, f.(x, y'), 6)); incremental = false) savefigs("contour", ans) # hide ``` @@ -160,9 +151,9 @@ savefigs("contour", ans) # hide ```@example pgf using StatsBase: Histogram, fit -pgf.Axis(pgf.Plot(pgf.Table(fit(Histogram, randn(100), closed = :left)); +Axis(Plot(Table(fit(Histogram, randn(100), closed = :left)); incremental = false), - pgf.@pgf { + @pgf { "ybar interval", "xticklabel interval boundaries", xticklabel = raw"$[\pgfmathprintnumber\tick,\pgfmathprintnumber\nexttick)$", @@ -181,19 +172,19 @@ savefigs("histogram-1d", ans) # hide ```@example pgf using StatsBase: Histogram, fit h = fit(Histogram, (randn(1000), randn(1000)), closed = :left) -@pgf.pgf pgf.Axis( +@pgf Axis( { view = (0, 90), colorbar, "colormap/jet" }, - pgf.Plot3( + Plot3( { surf, shader = "flat", }, - pgf.Table(h); + Table(h); incremental = false ) ) diff --git a/docs/src/examples/tables.md b/docs/src/examples/tables.md index 5261a2c5..77b19787 100644 --- a/docs/src/examples/tables.md +++ b/docs/src/examples/tables.md @@ -2,20 +2,13 @@ `Table`s are coordinates in a tabular format (essentially a matrix), optionally with named columns. They have various constructors, for direct construction and also for conversion from other types. -```jl -import PGFPlotsX -const pgf = PGFPlotsX -using LaTeXStrings -``` ```@setup pgf -import PGFPlotsX -const pgf = PGFPlotsX -using LaTeXStrings +using PGFPlotsX savefigs = (figname, obj) -> begin - pgf.save(figname * ".pdf", obj) + PGFPlotsX.save(figname * ".pdf", obj) run(`pdf2svg $(figname * ".pdf") $(figname * ".svg")`) - pgf.save(figname * ".tex", obj); + PGFPlotsX.save(figname * ".tex", obj); return nothing end ``` @@ -34,7 +27,7 @@ y = sin.(x) You can pass these coordinates in unnamed columns: ```@example pgf -pgf.Plot(pgf.Table([x, y]); incremental = false) +Plot(Table([x, y]); incremental = false) savefigs("table-unnamed-columns", ans) # hide ``` @@ -45,7 +38,7 @@ savefigs("table-unnamed-columns", ans) # hide or named columns: ```@example pgf -pgf.Plot(pgf.Table([:x => x, :y => y]); incremental = false) +Plot(Table([:x => x, :y => y]); incremental = false) savefigs("table-named-columns", ans) # hide ``` @@ -56,12 +49,12 @@ savefigs("table-named-columns", ans) # hide or rename using options: ```@example pgf -pgf.@pgf pgf.Plot( +@pgf Plot( { x = "a", y = "b", }, - pgf.Table([:a => x, :b => y]); + Table([:a => x, :b => y]); incremental = false) savefigs("table-dict-rename", ans) # hide ``` @@ -75,18 +68,18 @@ In the example below, we use a matrix of values with edge vectors, and omit the x = linspace(-1, 1, 20) z = @. 1 - √(abs2(x) + abs2(x')) z[z .≤ 0] .= -Inf -@pgf.pgf pgf.Axis( +@pgf Axis( { colorbar, "colormap/jet", "unbounded coords" = "jump" }, - pgf.Plot3( + Plot3( { surf, shader = "flat", }, - pgf.Table(x, x, z); + Table(x, x, z); incremental = false ) ) diff --git a/docs/src/index.md b/docs/src/index.md index d9ea246c..53770480 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -23,9 +23,3 @@ For saving (or showing) png figures you need `pdftoppm` which should be installe !!! note If you installed a new latex engine, `pdf2svg` or `pdftoppm` after you installed *PGFPlotsX* you need to run `Pkg.build("PGFPlotsX")` for this to be reflected. - -## Manual Outline - -!!! note - `PGFPlotsX` does not export anything. In the manual we assume that the command - `import PGFPlotsX; const pgf = PGFPlotsX` has been run diff --git a/docs/src/man/options.md b/docs/src/man/options.md index e58666da..608e160c 100644 --- a/docs/src/man/options.md +++ b/docs/src/man/options.md @@ -25,11 +25,11 @@ where a string represents a key without a value (e.g. `"very thick"`) and a pair This works well when the options are few and there is only one level of options in the object. ```julia-repl -julia> c = pgf.Coordinates([1,2,3], [2, 4, 8]); +julia> c = Coordinates([1,2,3], [2, 4, 8]); -julia> p = pgf.Plot(c, "very thick", "mark" => "halfcircle") +julia> p = Plot(c, "very thick", "mark" => "halfcircle") -julia> pgf.print_tex(p); # print_tex is typically not called from user code +julia> print_tex(p); # print_tex is typically not called from user code \addplot+[very thick, mark={halfcircle}] coordinates { (1, 2) @@ -47,7 +47,7 @@ Instead, we provide a macro `@pgf` so that options can be entered similarly to h The previous example is then written as ```julia-repl -pgf.@pgf pgf.Plot(c, +@pgf Plot(c, { very_thick, mark = "halfcircle" @@ -57,7 +57,7 @@ pgf.@pgf pgf.Plot(c, A more complicated example is: ```julia-repl -pgf.@pgf a = pgf.Axis(pgf.Plot(c), +@pgf a = Axis(Plot(c), { "axis background/.style" = { @@ -73,7 +73,7 @@ pgf.@pgf a = pgf.Axis(pgf.Plot(c), which is printed as ```julia-repl -julia> pgf.print_tex(a) +julia> print_tex(a) \begin{axis}[axis background/.style={shade, top color={gray}, bottom color={white}}, ymode={log}] \addplot+[] coordinates { @@ -105,16 +105,16 @@ The following transformations of keys/values are done when the options are writt It is sometimes convenient to set and get options after an object has been created. ```julia-repl -julia> c = pgf.Coordinates([1,2,3], [2, 4, 8]); +julia> c = Coordinates([1,2,3], [2, 4, 8]); -julia> p = pgf.Plot(c) +julia> p = Plot(c) julia> p["fill"] = "blue"; julia> p["fill"]; "blue" -julia> pgf.@pgf p["axis background/.style"] = { shade, top_color = "gray", bottom_color = "white" }; +julia> @pgf p["axis background/.style"] = { shade, top_color = "gray", bottom_color = "white" }; julia> p["axis background/.style"]["top_color"]; "gray" @@ -125,7 +125,7 @@ julia> delete!(p, "fill"); julia> p -julia> pgf.print_tex(p) +julia> print_tex(p) \addplot+[axis background/.style={shade, top color={gray}, bottom color={white}}, very tick] coordinates { (1, 2) @@ -138,13 +138,13 @@ julia> pgf.print_tex(p) You can also merge in options that have been separately created using `merge!` ```julia-repl -julia> a = pgf.Axis(); +julia> a = Axis(); -julia> pgf.@pgf opts = {xmin = 0, ymax = 1, ybar}; +julia> @pgf opts = {xmin = 0, ymax = 1, ybar}; julia> merge!(a, opts) -julia> pgf.print_tex(a) +julia> print_tex(a) \begin{axis}[xmin={0}, ymax={1}, ybar] \end{axis} ``` diff --git a/docs/src/man/save.md b/docs/src/man/save.md index 88d0cce2..1d80c368 100644 --- a/docs/src/man/save.md +++ b/docs/src/man/save.md @@ -20,7 +20,7 @@ If you wish to disable this, run `pgf.enable_interactive(false)`. Figures can be exported to files using ```jlcon -pgf.save(filename::String, figure; include_preamble::Bool = true, dpi = 150) +PGFPlotsX.save(filename::String, figure; include_preamble::Bool = true, dpi = 150) ``` where the file extension of `filename` determines the file type (can be `.pdf`, `.svg` or `.tex`, or the standalone `tikz` file extensions below), `include_preamble` sets if the preamble should be included in the output (only relevant for `tex` export) and `dpi` determines the dpi of the figure (only relevant for `png` export). diff --git a/docs/src/man/structs.md b/docs/src/man/structs.md index 3fba8c81..0f8846b7 100644 --- a/docs/src/man/structs.md +++ b/docs/src/man/structs.md @@ -26,21 +26,21 @@ Examples: ```jldoctest julia> x = [1, 2, 3]; y = [2, 4, 8]; z = [-1, -2, -3]; -julia> pgf.print_tex(pgf.Coordinates(x, y)) +julia> print_tex(Coordinates(x, y)) coordinates { (1, 2) (2, 4) (3, 8) } -julia> pgf.print_tex(pgf.Coordinates(x, y, z)) +julia> print_tex(Coordinates(x, y, z)) coordinates { (1, 2, -1) (2, 4, -2) (3, 8, -3) } -julia> pgf.print_tex(pgf.Coordinates(x, x -> x^3)) +julia> print_tex(Coordinates(x, x -> x^3)) coordinates { (1, 1) @@ -48,15 +48,15 @@ julia> pgf.print_tex(pgf.Coordinates(x, x -> x^3)) (3, 27) } -julia> pgf.print_tex(pgf.Coordinates([(1.0, 2.0), (2.0, 4.0)])) +julia> print_tex(Coordinates([(1.0, 2.0), (2.0, 4.0)])) coordinates { (1.0, 2.0) (2.0, 4.0) } -julia> c = pgf.Coordinates(x, y, xerror = [0.2, 0.3, 0.5], yerror = [0.2, 0.1, 0.5]); +julia> c = Coordinates(x, y, xerror = [0.2, 0.3, 0.5], yerror = [0.2, 0.1, 0.5]); -julia> pgf.print_tex(c) +julia> print_tex(c) coordinates { (1, 2)+-(0.2, 0.2) (2, 4)+-(0.3, 0.1) @@ -72,9 +72,9 @@ An `Expression` is a string, representing a function and is written in a way LaT Example: ```jldoctest -julia> ex = pgf.Expression("exp(-x^2)"); +julia> ex = Expression("exp(-x^2)"); -julia> pgf.print_tex(ex) +julia> print_tex(ex) {exp(-x^2)} ``` @@ -85,9 +85,9 @@ A table represents a matrix of data where each column is labeled. It can simply Examples: ```jldoctest -julia> t = pgf.Table("data.dat", "x" => "Dof"); +julia> t = Table("data.dat", "x" => "Dof"); -julia> pgf.print_tex(t) +julia> print_tex(t) table [x={Dof}] {data.dat} ``` @@ -95,9 +95,9 @@ julia> pgf.print_tex(t) Inline data is constructed using a keyword constructor: ```jldoctest -julia> t = pgf.Table("x" => "Dof", "y" => "Err"; Dof = rand(3), Err = rand(3)); +julia> t = Table("x" => "Dof", "y" => "Err"; Dof = rand(3), Err = rand(3)); -julia> pgf.print_tex(t) +julia> print_tex(t) table [x={Dof}, y={Err}] {Dof Err 0.6073590230719768 0.36281513247882136 @@ -116,7 +116,7 @@ If you load the DataFrames package, you can also create tables from data frames, Example: ```juliadoctest -julia> pgf.print_tex(pgf.Graphics("img.png")) +julia> print_tex(Graphics("img.png")) graphics [] {img.png} ``` @@ -132,9 +132,9 @@ A keyword argument `incremental::Bool` is used to determine if `\addplot+` (defa Example: ```jldoctest -julia> p = pgf.@pgf pgf.Plot(pgf.Table("plotdata/invcum.dat"), { blue }; incremental = false); +julia> p = @pgf Plot(Table("plotdata/invcum.dat"), { blue }; incremental = false); -julia> pgf.print_tex(p) +julia> print_tex(p) \addplot[blue] table [] {plotdata/invcum.dat} @@ -151,9 +151,9 @@ Example: ```jldoctest julia> x, y, z = rand(3), rand(3), rand(3); -julia> p = pgf.@pgf pgf.Plot3(pgf.Coordinates(x,y,z), { very_thick }) +julia> p = @pgf Plot3(Coordinates(x,y,z), { very_thick }) -julia> pgf.print_tex(p) +julia> print_tex(p) \addplot3+[very thick] coordinates { (0.7399041050338018, 0.4333342656950161, 0.31102760595379864) @@ -178,22 +178,22 @@ julia> pgf.print_tex(p) Examples: ```jldoctest -julia> pgf.@pgf a = pgf.Axis( pgf.Plot( pgf.Expression("x^2")), { +julia> @pgf a = Axis( Plot( Expression("x^2")), { xlabel = "x" ylabel = "y" title = "Figure" }) -julia> pgf.print_tex(a) +julia> print_tex(a) \begin{axis}[xlabel={x}, ylabel={y}, title={Figure}] \addplot+[] {x^2} ; \end{axis} -julia> push!(a, pgf.Plot( pgf.Table("data.dat"))); +julia> push!(a, Plot( Table("data.dat"))); -julia> pgf.print_tex(a) +julia> print_tex(a) \begin{axis}[xlabel={x}, ylabel={y}, title={Figure}] \addplot+[] {x^2} @@ -215,13 +215,13 @@ A `GroupPlot` is a way of grouping multiple plots in one figure. Example: ```jldoctest -julia> pgf.@pgf gp = pgf.GroupPlot({group_style = { group_size = "2 by 1",}, height = "6cm", width = "6cm"}); +julia> @pgf gp = GroupPlot({group_style = { group_size = "2 by 1",}, height = "6cm", width = "6cm"}); julia> for (expr, data) in zip(["x^2", "exp(x)"], ["data1.dat", "data2.dat"]) - push!(gp, [pgf.Plot(pgf.Expression(expr)), pgf.Plot(pgf.Table(data))]) + push!(gp, [Plot(Expression(expr)), Plot(Table(data))]) end; -julia> pgf.print_tex(gp) +julia> print_tex(gp) \begin{groupplot}[group style={group size={2 by 1}}, height={6cm}, width={6cm}] \nextgroupplot[] @@ -248,13 +248,13 @@ In order to add options to the `\nextgroupplot` call simply add arguments in an "option like way" (using strings / pairs / `@pgf`) when you `push!` ```jldoctest -julia> pgf.@pgf gp = pgf.GroupPlot({group_style = { group_size = "1 by 1",}, height = "6cm", width = "6cm"}); +julia> @pgf gp = GroupPlot({group_style = { group_size = "1 by 1",}, height = "6cm", width = "6cm"}); -julia> pgf.@pgf for (expr, data) in zip(["x^2"], ["data2.dat"]) - push!(gp, [pgf.Plot(pgf.Expression(expr)), pgf.Plot(pgf.Table(data))], {title = "Data $data"}) +julia> @pgf for (expr, data) in zip(["x^2"], ["data2.dat"]) + push!(gp, [Plot(Expression(expr)), Plot(Table(data))], {title = "Data $data"}) end; -julia> pgf.print_tex(gp) +julia> print_tex(gp) \begin{groupplot}[group style={group size={1 by 1}}, height={6cm}, width={6cm}] \nextgroupplot[title={Data data2.dat}] @@ -275,7 +275,7 @@ A `PolarAxis` plot data on a polar grid. Example: ```jldoctest -julia> pgf.PolarAxis( pgf.Plot( pgf.Coordinates([0, 90, 180, 270], [1, 1, 1, 1]))) +julia> PolarAxis( Plot( Coordinates([0, 90, 180, 270], [1, 1, 1, 1]))) ``` ### `Legend` @@ -285,7 +285,7 @@ A `Legend` can be used to add legends to plots. Example: ```jldoctest -julia> pgf.print_tex(pgf.Legend(["Plot A", "Plot B"])) +julia> print_tex(Legend(["Plot A", "Plot B"])) \legend{Plot A, Plot B} ``` @@ -296,9 +296,9 @@ A `TikzPicture` can contain multiple `Axis`'s or `GroupPlot`'s. Example: ```jldoctest -julia> tp = pgf.TikzPicture( pgf.Axis( pgf.Plot( pgf.Coordinates(rand(5), rand(5)))), "scale" => 1.5) +julia> tp = TikzPicture( Axis( Plot( Coordinates(rand(5), rand(5)))), "scale" => 1.5) -julia> pgf.print_tex(tp) +julia> print_tex(tp) \begin{tikzpicture}[scale={1.5}] \begin{axis}[] \addplot+[] @@ -323,7 +323,7 @@ A very simple example where we simply create a `TikzDocument` with a string in i Normally you would also push `Axis`'s that contain plots. ```julia-repl -julia> td = pgf.TikzDocument(); +julia> td = TikzDocument(); julia> push!(td, "Hello World") ``` diff --git a/docs/src/man/troubleshooting.md b/docs/src/man/troubleshooting.md deleted file mode 100644 index e69de29b..00000000 diff --git a/src/PGFPlotsX.jl b/src/PGFPlotsX.jl index ed692940..97c62b18 100644 --- a/src/PGFPlotsX.jl +++ b/src/PGFPlotsX.jl @@ -12,6 +12,12 @@ using DocStringExtensions using Parameters using Requires +export TikzDocument, TikzPicture +export Axis, GroupPlot, PolarAxis +export Plot, Plot3, Expression, EmptyLine, Coordinates, + Table, Graphics, Legend +export @pgf, print_tex, latexengine, latexengine!, CUSTOM_PREAMBLE, push_preamble! + const DEBUG = haskey(ENV, "PGFPLOTSX_DEBUG") const CUSTOM_PREAMBLE_PATH = joinpath(@__DIR__, "..", "deps", "custom_preamble.tex") const PGFOption = Union{Pair, String, OrderedDict} diff --git a/src/tikzdocument.jl b/src/tikzdocument.jl index 3deba8ce..03d59e32 100644 --- a/src/tikzdocument.jl +++ b/src/tikzdocument.jl @@ -269,11 +269,11 @@ if HAVE_PDFTOPPM rm(filename; force = true) end end - _DISPLAY_PDF = true enable_interactive(v::Bool) = global _DISPLAY_PDF = v _is_ijulia() = isdefined(Main, :IJulia) && Main.IJulia.inited -_is_juno() = isdefined(Main, :Juno) && Main.Juno.isactive() +_is_juno() = isdefined(Main, :Juno) && Main.Juno.isactive() +_is_vscode() = isdefined(Main, :_vscodeserver) function Base.show(io::IO, ::MIME"text/plain", p::_SHOWABLE) diff --git a/test/runtests.jl b/test/runtests.jl index 64be87d1..75e81441 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,14 +8,12 @@ using DataStructures: OrderedDict using LaTeXStrings using RDatasets -const pgf = PGFPlotsX - if get(ENV, "CI", false) == true - pgf.latexengine!(pgf.PDFLATEX) + PGFPlotsX.latexengine!(PGFPlotsX.PDFLATEX) end -@show pgf.latexengine -pgf.latexengine!(pgf.PDFLATEX) +@show PGFPlotsX.latexengine +PGFPlotsX.latexengine!(PGFPlotsX.PDFLATEX) include("test_macros.jl") diff --git a/test/test_build.jl b/test/test_build.jl index 372b6493..077c76a8 100644 --- a/test/test_build.jl +++ b/test/test_build.jl @@ -32,20 +32,20 @@ is_svg_file(filename) = is_file_starting_with(filename, r"", 2) test_preamble_env = "test preamble env" test_preamble_var = "test preamble var" - push!(pgf.CUSTOM_PREAMBLE, test_preamble_var) + push!(CUSTOM_PREAMBLE, test_preamble_var) print(f, test_preamble_env) close(f) - td = pgf.TikzDocument() + td = TikzDocument() io = IOBuffer() - pgf.savetex(io, td) + PGFPlotsX.savetex(io, td) texstring = String(take!(io)) @test contains(texstring, test_preamble_env) @test contains(texstring, test_preamble_var) finally - empty!(pgf.CUSTOM_PREAMBLE) + empty!(CUSTOM_PREAMBLE) end end end @@ -55,17 +55,17 @@ end tmp = tempname() mktempdir() do dir cd(dir) do - a = pgf.Axis(pgf.Plot(pgf.Expression("x^2"))) - pgf.save("$tmp.tex", a) + a = Axis(Plot(Expression("x^2"))) + PGFPlotsX.save("$tmp.tex", a) @test is_tex_document("$tmp.tex") println(readstring("$tmp.tex")) - pgf.save("$tmp.png", a) + PGFPlotsX.save("$tmp.png", a) @test is_png_file("$tmp.png") - pgf.save("$tmp.pdf", a) + PGFPlotsX.save("$tmp.pdf", a) @test is_pdf_file("$tmp.pdf") - pgf.save("$tmp.svg", a) + PGFPlotsX.save("$tmp.svg", a) @test is_svg_file("$tmp.svg") - pgf.save("$tmp.tikz", a) + PGFPlotsX.save("$tmp.tikz", a) @test is_tikz_standalone("$tmp.tikz") let tikz_lines = readlines("$tmp.tikz") @@ -82,8 +82,8 @@ end expr = "-2.051^3*1000./(2*3.1415*(2.99*10^2)^2)/(x^2*cos(y)^2)" mktempdir() do dir cd(dir) do - pgf.@pgf p = - pgf.Axis(pgf.Plot3(pgf.Expression(expr), + @pgf p = + Axis(Plot3(Expression(expr), { contour_gnuplot = { number = 30, @@ -99,7 +99,7 @@ end y_domain = "74:87.9", view = (0, 90), }) - pgf.save(tmp_pdf, p) + PGFPlotsX.save(tmp_pdf, p) @test is_pdf_file(tmp_pdf) rm(tmp_pdf) end diff --git a/test/test_elements.jl b/test/test_elements.jl index 4c5fb320..7ae21af8 100644 --- a/test/test_elements.jl +++ b/test/test_elements.jl @@ -1,7 +1,7 @@ "Invoke print_tex with the given arguments, collect the results in a string." function repr_tex(args...) io = IOBuffer() - pgf.print_tex(io, args...) + print_tex(io, args...) String(take!(io)) end @@ -43,88 +43,88 @@ end end @testset "coordinate" begin - @test_throws ArgumentError pgf.Coordinate((1, )) # dimension not 2 or 3 - @test_throws ArgumentError pgf.Coordinate((NaN, 1)) # not finite - @test_throws ArgumentError pgf.Coordinate((1, 2); # can't specify both + @test_throws ArgumentError PGFPlotsX.Coordinate((1, )) # dimension not 2 or 3 + @test_throws ArgumentError PGFPlotsX.Coordinate((NaN, 1)) # not finite + @test_throws ArgumentError PGFPlotsX.Coordinate((1, 2); # can't specify both error = (0, 0), errorplus = (0, 0)) - @test_throws MethodError pgf.Coordinates((1, 2); error = (3, )) # incompatible dims - @test squashed_repr_tex(pgf.Coordinate((1, 2))) == "(1, 2)" - @test squashed_repr_tex(pgf.Coordinate((1, 2); error = (3, 4))) == "(1, 2) +- (3, 4)" - @test squashed_repr_tex(pgf.Coordinate((1, 2); errorminus = (3, 4))) == + @test_throws MethodError Coordinates((1, 2); error = (3, )) # incompatible dims + @test squashed_repr_tex(PGFPlotsX.Coordinate((1, 2))) == "(1, 2)" + @test squashed_repr_tex(PGFPlotsX.Coordinate((1, 2); error = (3, 4))) == "(1, 2) +- (3, 4)" + @test squashed_repr_tex(PGFPlotsX.Coordinate((1, 2); errorminus = (3, 4))) == "(1, 2) -= (3, 4)" - @test squashed_repr_tex(pgf.Coordinate((1, 2); + @test squashed_repr_tex(PGFPlotsX.Coordinate((1, 2); errorminus = (3, 4), errorplus = (5, 6))) == "(1, 2) += (5, 6) -= (3, 4)" - @test squashed_repr_tex(pgf.Coordinate((1, 2); meta = "blue")) == "(1, 2) [blue]" + @test squashed_repr_tex(PGFPlotsX.Coordinate((1, 2); meta = "blue")) == "(1, 2) [blue]" end @testset "coordinates and convenience constructors" begin - @test_throws ArgumentError pgf.Coordinates([(1, 2), (1, 2, 3)]) # incompatible dims - @test_throws ArgumentError pgf.Coordinates([(1, 2), "invalid"]) # invalid value + @test_throws ArgumentError Coordinates([(1, 2), (1, 2, 3)]) # incompatible dims + @test_throws ArgumentError Coordinates([(1, 2), "invalid"]) # invalid value # from Vectors and AbstractVectors - @test pgf.Coordinates([1, 2], [3.0, 4.0]).data == pgf.Coordinate.([(1, 3.0), (2, 4.0)]) - @test pgf.Coordinates(1:2, 3:4).data == pgf.Coordinate.([(1, 3), (2, 4)]) + @test Coordinates([1, 2], [3.0, 4.0]).data == PGFPlotsX.Coordinate.([(1, 3.0), (2, 4.0)]) + @test Coordinates(1:2, 3:4).data == PGFPlotsX.Coordinate.([(1, 3), (2, 4)]) # skip empty - @test pgf.Coordinates([(2, 3), (), nothing]).data == - [pgf.Coordinate((2, 3)), pgf.EmptyLine(), pgf.EmptyLine()] - @test pgf.Coordinates(1:2, 3:4, (1:2)./((3:4)')).data == - pgf.Coordinates(Any[1, 2, NaN, 1, 2, NaN], + @test Coordinates([(2, 3), (), nothing]).data == + [PGFPlotsX.Coordinate((2, 3)), EmptyLine(), EmptyLine()] + @test Coordinates(1:2, 3:4, (1:2)./((3:4)')).data == + Coordinates(Any[1, 2, NaN, 1, 2, NaN], Any[3, 3, NaN, 4, 4, NaN], Any[1/3, 2/3, NaN, 1/4, 2/4, NaN]).data # from iterables - @test pgf.Coordinates(enumerate(3:4)).data == pgf.Coordinate.([(1, 3), (2, 4)]) - @test pgf.Coordinates((x, 1/x) for x in -1:1).data == - [pgf.Coordinate((-1, -1.0)), pgf.EmptyLine(), pgf.Coordinate((1, 1.0))] + @test Coordinates(enumerate(3:4)).data == PGFPlotsX.Coordinate.([(1, 3), (2, 4)]) + @test Coordinates((x, 1/x) for x in -1:1).data == + [PGFPlotsX.Coordinate((-1, -1.0)), EmptyLine(), PGFPlotsX.Coordinate((1, 1.0))] let x = 1:3, y = -1:1, z = x ./ y - @test pgf.Coordinates(x, y, z).data == - pgf.Coordinates((x, y, x / y) for (x,y) in zip(x, y)).data + @test Coordinates(x, y, z).data == + Coordinates((x, y, x / y) for (x,y) in zip(x, y)).data end end @testset "tables" begin # compare results to these using ≅, defined above - table_named_noopt = pgf.Table(OrderedDict{Any, Any}(), hcat(1:10, 11:20), + table_named_noopt = Table(OrderedDict{Any, Any}(), hcat(1:10, 11:20), ["a", "b"], Int[]) - table_unnamed_noopt = pgf.Table(OrderedDict{Any, Any}(), hcat(1:10, 11:20), + table_unnamed_noopt = Table(OrderedDict{Any, Any}(), hcat(1:10, 11:20), nothing, Int[]) - opt = pgf.@pgf { meaningless = "option" } - table_named_opt = pgf.Table(opt, hcat(1:10, 11:20), ["a", "b"], Int[]) + opt = @pgf { meaningless = "option" } + table_named_opt = Table(opt, hcat(1:10, 11:20), ["a", "b"], Int[]) # named columns, without options - @test pgf.Table(:a => 1:10, :b => 11:20) ≅ table_named_noopt - @test pgf.Table(; a = 1:10, b = 11:20) ≅ table_named_noopt - @test pgf.Table([:a => 1:10, :b => 11:20]) ≅ table_named_noopt - @test pgf.Table(hcat(1:10, 11:20); colnames = [:a, :b]) ≅ table_named_noopt + @test Table(:a => 1:10, :b => 11:20) ≅ table_named_noopt + @test Table(; a = 1:10, b = 11:20) ≅ table_named_noopt + @test Table([:a => 1:10, :b => 11:20]) ≅ table_named_noopt + @test Table(hcat(1:10, 11:20); colnames = [:a, :b]) ≅ table_named_noopt # named columns, with options - @test pgf.Table(opt, :a => 1:10, :b => 11:20) ≅ table_named_opt - @test pgf.Table(opt, [:a => 1:10, :b => 11:20]) ≅ table_named_opt - @test pgf.Table(opt, hcat(1:10, 11:20); colnames = [:a, :b]) ≅ table_named_opt + @test Table(opt, :a => 1:10, :b => 11:20) ≅ table_named_opt + @test Table(opt, [:a => 1:10, :b => 11:20]) ≅ table_named_opt + @test Table(opt, hcat(1:10, 11:20); colnames = [:a, :b]) ≅ table_named_opt # unnamed columns, without options - @test pgf.Table(1:10, 11:20) ≅ table_unnamed_noopt - @test pgf.Table([1:10, 11:20]) ≅ table_unnamed_noopt - @test pgf.Table(hcat(1:10, 11:20)) ≅ table_unnamed_noopt + @test Table(1:10, 11:20) ≅ table_unnamed_noopt + @test Table([1:10, 11:20]) ≅ table_unnamed_noopt + @test Table(hcat(1:10, 11:20)) ≅ table_unnamed_noopt # matrix and edges let x = randn(10), y = randn(5), z = cos.(x .+ y') - @test pgf.Table(x, y, z) ≅ pgf.Table(OrderedDict{Any, Any}(), - hcat(pgf.matrix_xyz(x, y, z)...), + @test Table(x, y, z) ≅ Table(OrderedDict{Any, Any}(), + hcat(PGFPlotsX.matrix_xyz(x, y, z)...), ["x", "y", "z"], 10) end # dataframe - @test pgf.Table(DataFrame(a = 1:5, b = 6:10)) ≅ - pgf.Table(OrderedDict{Any, Any}(), hcat(1:5, 6:10), ["a", "b"], 0) + @test Table(DataFrame(a = 1:5, b = 6:10)) ≅ + Table(OrderedDict{Any, Any}(), hcat(1:5, 6:10), ["a", "b"], 0) # can't determine if it is named or unnamed - @test_throws ArgumentError pgf.Table([1:10, :a => 11:20]) + @test_throws ArgumentError Table([1:10, :a => 11:20]) - @test squashed_repr_tex(pgf.Table(OrderedDict{Any, Any}(), + @test squashed_repr_tex(Table(OrderedDict{Any, Any}(), [1 NaN; -Inf 4.0], ["xx", "yy"], @@ -134,7 +134,7 @@ end @testset "tablefile" begin path = "somefile.dat" _abspath = abspath(path) - @test squashed_repr_tex(pgf.Table(pgf.@pgf({x = "a", y = "b"}), path)) == + @test squashed_repr_tex(Table(@pgf({x = "a", y = "b"}), path)) == "table [x={a}, y={b}]\n{$(_abspath)}" - @test squashed_repr_tex(pgf.Table("somefile.dat")) == "table []\n{$(_abspath)}" + @test squashed_repr_tex(Table("somefile.dat")) == "table []\n{$(_abspath)}" end diff --git a/test/test_macros.jl b/test/test_macros.jl index c6ae4f70..245f4b0c 100644 --- a/test/test_macros.jl +++ b/test/test_macros.jl @@ -18,10 +18,10 @@ od(args...) = OrderedDict{Any, Any}(args...) @testset "pgf tests" begin a = 1 b = 2 - @test pgf.@pgf { xmax = a + b, title = "42", justkey } == + @test @pgf { xmax = a + b, title = "42", justkey } == od("xmax" => 3, "title" => "42", "justkey" => nothing) f(x...) = tuple(x...) - @test pgf.@pgf f({ look, we, are = f(1, 2, 3), + @test @pgf f({ look, we, are = f(1, 2, 3), nesting = { stuff = 9 }}) == (od("look" => nothing,