From 219465d599af93caa45f6b348050515588752f99 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Mon, 11 May 2020 16:52:00 +0200 Subject: [PATCH] fix contours (#2692) * fix 2d-contour * fix filled contours (colorbar is off) * activate fixed examples --- src/backends/pgfplotsx.jl | 25 ++++++++----------------- src/examples.jl | 2 -- src/utils.jl | 2 +- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 4486330c..2f2e2d1e 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -288,7 +288,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) extra_series = wraptuple(pop!(extra_series_opt,:add)) end series_opt = merge(series_opt, PGFPlotsX.Options(extra_series_opt...)) - if RecipesPipeline.is3d(series) || st == :heatmap + if RecipesPipeline.is3d(series) || st in (:heatmap, :contour) series_func = PGFPlotsX.Plot3 else series_func = PGFPlotsX.Plot @@ -297,7 +297,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) !isfilledcontour(series) && series[:ribbon] === nothing push!(series_opt, "area legend" => nothing) end - if st == :heatmap + if st in (:heatmap, :contour) push!(axis.options, "view" => "{0}{90}") end # treat segments @@ -342,12 +342,13 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) end segment_opt = merge(segment_opt, pgfx_marker(opt, i)) end - if st == :shape || isfilledcontour(series) + if st == :shape segment_opt = merge(segment_opt, pgfx_fillstyle(opt, i)) end # add fillrange if sf !== nothing && - !isfilledcontour(series) && series[:ribbon] === nothing + !isfilledcontour(series) && + series[:ribbon] === nothing if sf isa Number || sf isa AVec pgfx_fillrange_series!( axis, @@ -596,8 +597,8 @@ function pgfx_series_coordinates!( xs, ys, zs = collect(args) push!( segment_opt, - "contour filled" => PGFPlotsX.Options("labels" => opt[:contour_labels]), - "point meta" => "explicit", + "contour filled" => PGFPlotsX.Options(), # labels not supported + "patch type" => "bilinear", "shader" => "flat", ) if opt[:levels] isa Number @@ -606,17 +607,7 @@ function pgfx_series_coordinates!( push!(segment_opt["contour filled"], "levels" => opt[:levels]) end - cs = join( - [ - join(["($x, $y) [$(zs[j, i])]" for (j, x) in enumerate(xs)], " ") for (i, y) in enumerate(ys) - ], - "\n\n", - ) - """ - coordinates { - $cs - }; - """ + PGFPlotsX.Coordinates(args...) end ## pgfx_get_linestyle(k) = get( diff --git a/src/examples.jl b/src/examples.jl index 4b1f7e49..d41add7f 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -998,13 +998,11 @@ _backend_skips = Dict( 6, # images 10, # histogram2d 16, # pgfplots thinks the upper panel is too small - 22, # contourf 25, # @df 30, # @df 31, # animation 32, # spy 38, # histogram2d - 45, # wireframe ], ) diff --git a/src/utils.jl b/src/utils.jl index e83a9f86..d24ed3a7 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -487,7 +487,7 @@ end hascolorbar(series::Series) = colorbar_style(series) !== nothing hascolorbar(sp::Subplot) = sp[:colorbar] != :none && any(hascolorbar(s) for s in series_list(sp)) -iscontour(series::Series) = series[:seriestype] == :contour +iscontour(series::Series) = series[:seriestype] in (:contour, :contour3d) isfilledcontour(series::Series) = iscontour(series) && series[:fillrange] !== nothing function contour_levels(series::Series, clims)