From 1b70fb18e4c9d78d9ab7e5692d66d06d6194d927 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Tue, 18 Aug 2020 12:42:14 +0200 Subject: [PATCH] fix extra series in lens! (#2919) * fix extra series in lens! * include tests --- src/recipes.jl | 18 ++++++++++-------- test/runtests.jl | 1 + test/test_recipes.jl | 6 ++++++ 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 test/test_recipes.jl diff --git a/src/recipes.jl b/src/recipes.jl index 14beefac..331c5100 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -919,7 +919,7 @@ end @recipe function f(::Type{Val{:mesh3d}}, x, y, z) # As long as no i,j,k are supplied this should work with PyPlot and GR seriestype := :surface - if plotattributes[:connections] != nothing + if plotattributes[:connections] != nothing throw(ArgumentError("Giving triangles using the connections argument is only supported on Plotly backend.")) end () @@ -962,8 +962,12 @@ export lens! lens_index = last(plt.subplots)[:subplot_index] + 1 x1, x2 = plotattributes[:x] y1, y2 = plotattributes[:y] + backup = copy(plotattributes) + empty!(plotattributes) + + series_plotindex := backup[:series_plotindex] seriestype := :path - label := "" + primary := false linecolor := :lightgray bbx_mag = (x1 + x2) / 2 bby_mag = (y1 + y2) / 2 @@ -973,6 +977,7 @@ export lens! if xl1 < xi_lens < xl2 && yl1 < yi_lens < yl2 @series begin + primary := false subplot := sp_index x := [xi_mag, xi_lens] y := [yi_mag, yi_lens] @@ -981,6 +986,7 @@ export lens! end # add magnification shape @series begin + primary := false subplot := sp_index x := [x1, x1, x2, x2, x1] y := [y1, y2, y2, y1, y1] @@ -991,16 +997,13 @@ export lens! @series begin plotattributes = merge(plotattributes, copy(series.plotattributes)) subplot := lens_index - label := "" + primary := false xlims := (x1, x2) ylims := (y1, y2) () end end - backup = copy(plotattributes) - empty!(plotattributes) - seriestype := :path - series_plotindex := backup[:series_plotindex] + nothing end function intersection_point(xA, yA, xB, yB, h, w) @@ -1546,4 +1549,3 @@ julia> areaplot(1:3, [1 2 3; 7 8 9; 4 5 6], seriescolor = [:red :green :blue], f end end end - diff --git a/test/runtests.jl b/test/runtests.jl index 67b6e6b1..946f13fc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,6 +11,7 @@ import GeometryTypes, GeometryBasics using Dates include("test_axes.jl") +include("test_recipes.jl") include("test_hdf5plots.jl") include("test_pgfplotsx.jl") diff --git a/test/test_recipes.jl b/test/test_recipes.jl new file mode 100644 index 00000000..b1f34351 --- /dev/null +++ b/test/test_recipes.jl @@ -0,0 +1,6 @@ +using Plots, Test +@testset "lens!" begin + pl = plot(1:5) + lens!(pl, [1,2], [1,2], inset = (1, bbox(0.0,0.0,0.2,0.2))) + @test length(pl.series_list) == 4 +end # testset