From 6b7be5ae12b396730993a319fbb1e73f4b818964 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 6 Apr 2020 09:22:52 +0200 Subject: [PATCH 01/16] apply type recipe for AbstractVector{<:Number} --- Project.toml | 2 +- src/series.jl | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index a23555b5..fe8d147f 100644 --- a/Project.toml +++ b/Project.toml @@ -53,12 +53,12 @@ julia = "1" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb" Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44" +HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925" -HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" diff --git a/src/series.jl b/src/series.jl index 9a27c96b..db40971f 100644 --- a/src/series.jl +++ b/src/series.jl @@ -226,8 +226,7 @@ function _apply_type_recipe(plotattributes, v::Surface) end end -# don't do anything for datapoints or nothing -_apply_type_recipe(plotattributes, v::AbstractArray{<:DataPoint}, letter) = v +# don't do anything for nothing _apply_type_recipe(plotattributes, v::Nothing, letter) = v # axis args before type recipes should still be mapped to all axes From 5ff0a419ddd2e06207674984c891c8c760544ccc Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 6 Apr 2020 09:23:14 +0200 Subject: [PATCH 02/16] bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index fe8d147f..ab1054eb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Plots" uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" author = ["Tom Breloff (@tbreloff)"] -version = "1.0.0" +version = "1.0.1" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" From b433b76a8445e907472dfd3b01be7a7ce1f33243 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 6 Apr 2020 09:56:47 +0200 Subject: [PATCH 03/16] allow type recipes for numbers but not for reals --- src/series.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/series.jl b/src/series.jl index db40971f..23d13d77 100644 --- a/src/series.jl +++ b/src/series.jl @@ -228,6 +228,8 @@ end # don't do anything for nothing _apply_type_recipe(plotattributes, v::Nothing, letter) = v +_apply_type_recipe(plotattributes, v::AbstractArray{<:MaybeString}, letter) = v +_apply_type_recipe(plotattributes, v::AbstractArray{<:Union{Real, Nothing}}, letter) = v # axis args before type recipes should still be mapped to all axes function _preprocess_axis_args!(plotattributes) From a9d22cfb602a77c38b6700a7f6e0056b9b1d7e1e Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 6 Apr 2020 10:11:00 +0200 Subject: [PATCH 04/16] update comment --- src/series.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/series.jl b/src/series.jl index 23d13d77..40ec0213 100644 --- a/src/series.jl +++ b/src/series.jl @@ -226,7 +226,7 @@ function _apply_type_recipe(plotattributes, v::Surface) end end -# don't do anything for nothing +# don't do anything vectors of datapoints and for nothing _apply_type_recipe(plotattributes, v::Nothing, letter) = v _apply_type_recipe(plotattributes, v::AbstractArray{<:MaybeString}, letter) = v _apply_type_recipe(plotattributes, v::AbstractArray{<:Union{Real, Nothing}}, letter) = v From 0daed2402020be329314a222c7ad81a391a1fadc Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 6 Apr 2020 14:12:46 +0200 Subject: [PATCH 05/16] fix link --- src/args.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/args.jl b/src/args.jl index e4f137af..baa2a76c 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1015,7 +1015,7 @@ function preprocessArgs!(plotattributes::AKW) end # handle axes args for k in _axis_args - if haskey(plotattributes, k) + if haskey(plotattributes, k) && k !== :link v = plotattributes[k] for letter in (:x, :y, :z) lk = Symbol(letter, k) From 1b0fb955832f99f142f9c737efd065d4129e31ac Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 6 Apr 2020 14:26:22 +0200 Subject: [PATCH 06/16] add axes linking test --- src/examples.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/examples.jl b/src/examples.jl index ff55b586..37c9e19b 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -934,6 +934,18 @@ const _examples = PlotExample[ end, ], ), + PlotExample( + "Linked axes", + "", + [ + quote + begin + x = -5:0.1:5 + plot(plot(x, x->x^2), plot(x, x->sin(x)), layout = 2, link = :y) + end + end, + ], + ), ] # Some constants for PlotDocs and PlotReferenceImages From f118d0cd351ec7f6a4b6be1e4c2c1b1a59c511a2 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 6 Apr 2020 14:27:03 +0200 Subject: [PATCH 07/16] bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index ab1054eb..0b4ebefb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Plots" uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" author = ["Tom Breloff (@tbreloff)"] -version = "1.0.1" +version = "1.0.2" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" From 57a6f4303bc7dbf4fcc6fb6998e4c3a8c610266f Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Mon, 6 Apr 2020 15:44:06 +0200 Subject: [PATCH 08/16] special case LaTeXStrings --- Project.toml | 2 ++ src/backends/pgfplotsx.jl | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/Project.toml b/Project.toml index 0b4ebefb..45d54ec7 100644 --- a/Project.toml +++ b/Project.toml @@ -12,6 +12,7 @@ FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Measures = "442fdcdd-2543-5da2-b0f3-8c86c306513e" NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" @@ -37,6 +38,7 @@ FixedPointNumbers = "0.6, 0.7, 0.8" GR = "0.46, 0.47, 0.48" GeometryTypes = "0.7, 0.8" JSON = "0.21" +LaTeXStrings = "1" Measures = "0.3" NaNMath = "0.3" PGFPlotsX = "1.2.0" diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 672636c6..3cb2673b 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -1,4 +1,5 @@ using Contour: Contour +using LaTeXStrings using UUIDs Base.@kwdef mutable struct PGFPlotsXPlot is_created::Bool = false @@ -900,6 +901,12 @@ function pgfx_sanitize_string(s::AbstractString) s = replace(s, r"\\?\%" => "\\%") s = replace(s, r"\\?\_" => "\\_") s = replace(s, r"\\?\&" => "\\&") + s = replace(s, r"\\?\{" => "\\{") + s = replace(s, r"\\?\}" => "\\}") +end +function pgfx_sanitize_string(s::LaTeXString) + s = replace(s, r"\\?\#" => "\\#") + s = replace(s, r"\\?\%" => "\\%") end function pgfx_sanitize_plot!(plt) for (key, value) in plt.attr From 87b220e7473387626c44b044db55ecb410a0047d Mon Sep 17 00:00:00 2001 From: harryscholes Date: Mon, 6 Apr 2020 15:15:55 +0100 Subject: [PATCH 09/16] Fix #2487 --- src/shorthands.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shorthands.jl b/src/shorthands.jl index 81d290c7..230806a4 100644 --- a/src/shorthands.jl +++ b/src/shorthands.jl @@ -438,7 +438,7 @@ julia> plot(1:10) julia> annotate!([(7,3,"(7,3)"),(3,7,text("hey", 14, :left, :top, :green))]) ``` """ -annotate!(anns...; kw...) = plot!(; annotation = anns, kw...) +annotate!(anns...; kw...) = plot!(; annotation = collect(anns), kw...) annotate!(anns::AVec{T}; kw...) where {T<:Tuple} = plot!(; annotation = anns, kw...) "Flip the current plots' x axis" From f8d36363b4b625594a25a567645250aade817d28 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 6 Apr 2020 17:09:00 +0200 Subject: [PATCH 10/16] allow type recipes for numbers in surfaces --- src/series.jl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/series.jl b/src/series.jl index 40ec0213..df45576a 100644 --- a/src/series.jl +++ b/src/series.jl @@ -216,7 +216,10 @@ function _apply_type_recipe(plotattributes, v::AbstractArray, letter) end # special handling for Surface... need to properly unwrap and re-wrap -_apply_type_recipe(plotattributes, v::Surface{<:AMat{<:DataPoint}}) = v +_apply_type_recipe( + plotattributes, + v::Surface{<:AMat{<:Union{AbstractFloat, Integer, Missing}}}, +) = v function _apply_type_recipe(plotattributes, v::Surface) ret = _apply_type_recipe(plotattributes, v.surf) if typeof(ret) <: Formatted @@ -229,7 +232,11 @@ end # don't do anything vectors of datapoints and for nothing _apply_type_recipe(plotattributes, v::Nothing, letter) = v _apply_type_recipe(plotattributes, v::AbstractArray{<:MaybeString}, letter) = v -_apply_type_recipe(plotattributes, v::AbstractArray{<:Union{Real, Nothing}}, letter) = v +_apply_type_recipe( + plotattributes, + v::AbstractArray{<:Union{AbstractFloat, Integer, Missing}}, + letter, +) = v # axis args before type recipes should still be mapped to all axes function _preprocess_axis_args!(plotattributes) From 54d441b62a7fc660060d0cfe1403c6f73a014226 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 6 Apr 2020 17:10:27 +0200 Subject: [PATCH 11/16] bump versio --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 0b4ebefb..30da8343 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Plots" uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" author = ["Tom Breloff (@tbreloff)"] -version = "1.0.2" +version = "1.0.3" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" From 59e4129194738ef98fe4deaa8d58fb958f221518 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 6 Apr 2020 17:25:18 +0200 Subject: [PATCH 12/16] skip maybestrings --- src/series.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/series.jl b/src/series.jl index df45576a..0e021767 100644 --- a/src/series.jl +++ b/src/series.jl @@ -216,6 +216,7 @@ function _apply_type_recipe(plotattributes, v::AbstractArray, letter) end # special handling for Surface... need to properly unwrap and re-wrap +_apply_type_recipe(plotattributes, v::Surface{<:AMat{MaybeString}}, letter) = v _apply_type_recipe( plotattributes, v::Surface{<:AMat{<:Union{AbstractFloat, Integer, Missing}}}, From 3dd1c500cfd214e49ef4caf6d057965506b7c695 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 6 Apr 2020 17:40:31 +0200 Subject: [PATCH 13/16] fix ambiguity --- src/series.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/series.jl b/src/series.jl index 0e021767..7cd0a3f0 100644 --- a/src/series.jl +++ b/src/series.jl @@ -216,10 +216,9 @@ function _apply_type_recipe(plotattributes, v::AbstractArray, letter) end # special handling for Surface... need to properly unwrap and re-wrap -_apply_type_recipe(plotattributes, v::Surface{<:AMat{MaybeString}}, letter) = v _apply_type_recipe( plotattributes, - v::Surface{<:AMat{<:Union{AbstractFloat, Integer, Missing}}}, + v::Surface{<:AMat{<:Union{AbstractFloat, Integer, AbstractString, Missing}}}, ) = v function _apply_type_recipe(plotattributes, v::Surface) ret = _apply_type_recipe(plotattributes, v.surf) @@ -232,10 +231,9 @@ end # don't do anything vectors of datapoints and for nothing _apply_type_recipe(plotattributes, v::Nothing, letter) = v -_apply_type_recipe(plotattributes, v::AbstractArray{<:MaybeString}, letter) = v _apply_type_recipe( plotattributes, - v::AbstractArray{<:Union{AbstractFloat, Integer, Missing}}, + v::AbstractArray{<:Union{AbstractFloat, Integer, AbstractString, Missing}}, letter, ) = v From 6807f53a7e00098bdc7a56600155b054f7a7e1e9 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Mon, 6 Apr 2020 14:30:28 -0400 Subject: [PATCH 14/16] use -O1 for code in Plots.jl --- src/Plots.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Plots.jl b/src/Plots.jl index 152f0f24..5c960e19 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -1,5 +1,9 @@ module Plots +if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@optlevel")) + @eval Base.Experimental.@optlevel 1 +end + const _current_plots_version = VersionNumber(split(first(filter(line -> occursin("version", line), readlines(normpath(@__DIR__, "..", "Project.toml")))), "\"")[2]) using Reexport From 7bd97558dc514b2efa4bcc844849f21516fcbf22 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Mon, 6 Apr 2020 21:41:11 +0200 Subject: [PATCH 15/16] fix annotations --- src/backends/pgfplotsx.jl | 31 +++++++++++++++-------------- test/test_pgfplotsx.jl | 41 +++++++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 672636c6..1931343a 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -352,17 +352,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) series_index, ) end - # add series annotations - anns = series[:series_annotations] - for (xi, yi, str, fnt) in EachAnn(anns, series[:x], series[:y]) - pgfx_add_annotation!( - axis, - xi, - yi, - PlotText(str, fnt), - pgfx_thickness_scaling(series), - ) - end # add to legend? if sp[:legend] != :none leg_entry = if opt[:label] isa AVec @@ -388,15 +377,26 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) end end end # for segments - # add subplot annotations - for ann in sp[:annotations] + # add series annotations + anns = series[:series_annotations] + for (xi, yi, str, fnt) in EachAnn(anns, series[:x], series[:y]) pgfx_add_annotation!( axis, - locate_annotation(sp, ann...)..., - pgfx_thickness_scaling(sp), + xi, + yi, + PlotText(str, fnt), + pgfx_thickness_scaling(series), ) end end # for series + # add subplot annotations + for ann in sp[:annotations] + pgfx_add_annotation!( + axis, + locate_annotation(sp, ann...)..., + pgfx_thickness_scaling(sp), + ) + end push!(the_plot, axis) if length(plt.o.the_plot.elements) > 0 plt.o.the_plot.elements[1] = the_plot @@ -405,6 +405,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) end end # for subplots pgfx_plot.is_created = true + pgfx_plot.was_shown = false end # if return pgfx_plot end diff --git a/test/test_pgfplotsx.jl b/test/test_pgfplotsx.jl index c88ea2d7..65fe9902 100644 --- a/test/test_pgfplotsx.jl +++ b/test/test_pgfplotsx.jl @@ -245,15 +245,39 @@ end end # testset @testset "Annotations" begin y = rand(10) - plot( + pgfx_plot = plot( y, annotations = (3, y[3], Plots.text("this is \\#3", :left)), leg = false, ) + Plots._update_plot_object(pgfx_plot) + axis_content = Plots.pgfx_axes(pgfx_plot.o)[1].contents + nodes = filter(x -> !isa(x, PGFPlotsX.Plot), axis_content) + @test length(nodes) == 1 + mktempdir() do path + file_path =joinpath(path,"annotations.tex") + @test_nowarn savefig(pgfx_plot, file_path) + open(file_path) do io + lines = readlines(io) + @test count(s -> occursin("node", s), lines) == 1 + end + end annotate!([ (5, y[5], Plots.text("this is \\#5", 16, :red, :center)), (10, y[10], Plots.text("this is \\#10", :right, 20, "courier")), ]) + Plots._update_plot_object(pgfx_plot) + axis_content = Plots.pgfx_axes(pgfx_plot.o)[1].contents + nodes = filter(x -> !isa(x, PGFPlotsX.Plot), axis_content) + @test length(nodes) == 3 + mktempdir() do path + file_path =joinpath(path,"annotations.tex") + @test_nowarn savefig(pgfx_plot, file_path) + open(file_path) do io + lines = readlines(io) + @test count(s -> occursin("node", s), lines) == 3 + end + end annotation_plot = scatter!( range(2, stop = 8, length = 6), rand(6), @@ -267,9 +291,18 @@ end Plots.text("data", :green), ], ) - # mktempdir() do path - # @test_nowarn savefig(annotation_plot, path*"annotation.pdf") - # end + Plots._update_plot_object(annotation_plot) + axis_content = Plots.pgfx_axes(annotation_plot.o)[1].contents + nodes = filter(x -> !isa(x, PGFPlotsX.Plot), axis_content) + @test length(nodes) == 9 + mktempdir() do path + file_path =joinpath(path,"annotations.tex") + @test_nowarn savefig(annotation_plot, file_path) + open(file_path) do io + lines = readlines(io) + @test count(s -> occursin("node", s), lines) == 9 + end + end end # testset @testset "Ribbon" begin aa = rand(10) From 65c9a46c8da6277d12b8cd1651d1d6c2bd7a657f Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Mon, 6 Apr 2020 22:00:51 +0200 Subject: [PATCH 16/16] rely on require --- Project.toml | 2 -- src/backends/pgfplotsx.jl | 10 ++++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 45d54ec7..0b4ebefb 100644 --- a/Project.toml +++ b/Project.toml @@ -12,7 +12,6 @@ FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" -LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Measures = "442fdcdd-2543-5da2-b0f3-8c86c306513e" NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" @@ -38,7 +37,6 @@ FixedPointNumbers = "0.6, 0.7, 0.8" GR = "0.46, 0.47, 0.48" GeometryTypes = "0.7, 0.8" JSON = "0.21" -LaTeXStrings = "1" Measures = "0.3" NaNMath = "0.3" PGFPlotsX = "1.2.0" diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 3cb2673b..17aa4815 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -1,5 +1,4 @@ using Contour: Contour -using LaTeXStrings using UUIDs Base.@kwdef mutable struct PGFPlotsXPlot is_created::Bool = false @@ -904,9 +903,12 @@ function pgfx_sanitize_string(s::AbstractString) s = replace(s, r"\\?\{" => "\\{") s = replace(s, r"\\?\}" => "\\}") end -function pgfx_sanitize_string(s::LaTeXString) - s = replace(s, r"\\?\#" => "\\#") - s = replace(s, r"\\?\%" => "\\%") +@require LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" begin + using LaTeXStrings + function pgfx_sanitize_string(s::LaTeXString) + s = replace(s, r"\\?\#" => "\\#") + s = replace(s, r"\\?\%" => "\\%") + end end function pgfx_sanitize_plot!(plt) for (key, value) in plt.attr