From 755575b98858c1e6a7b87cd180959bd961494b28 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Mon, 19 Oct 2020 11:16:25 +0200 Subject: [PATCH] add series_projections of contour plots --- src/args.jl | 1 + src/backends/pgfplotsx.jl | 34 +++++++++++++++++++++++++++++----- src/utils.jl | 2 +- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/args.jl b/src/args.jl index b76fe860..7926749c 100644 --- a/src/args.jl +++ b/src/args.jl @@ -287,6 +287,7 @@ const _series_defaults = KW( :hover => nothing, # text to display when hovering over the data points :stride => (1,1), # array stride for wireframe/surface, the first element is the row stride and the second is the column stride. :connections => nothing, # tuple of arrays to specifiy connectivity of a 3d mesh + :series_projection => :none, # allows e.g. projection to planes in a 3D plot :extra_kwargs => Dict() ) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index d5caf807..a12c1289 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -202,7 +202,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) for series in series_list(sp) if hascolorbar(series) cg = get_colorgradient(series) - cm = pgfx_colormap(get_colorgradient(series)) + cm = pgfx_colormap(cg) PGFPlotsX.push_preamble!( pgfx_plot.the_plot, """\\pgfplotsset{ @@ -564,10 +564,34 @@ function pgfx_add_series!(::Val{:filledcontour}, axis, series_opt, series, serie end function pgfx_add_series!(::Val{:contour3d}, axis, series_opt, series, series_func, opt) - push!( - series_opt, - "contour prepared" => PGFPlotsX.Options("labels" => opt[:contour_labels]), - ) + isproj = opt[:series_projection] != :none + if isproj + proj_letter, lim_value = getproperty( + ( + xy = (:z, zlims(opt[:subplot])[1]), + yx = (:z, zlims(opt[:subplot])[2]), + yz = (:x, xlims(opt[:subplot])[1]), + zy = (:x, xlims(opt[:subplot])[2]), + xz = (:y, ylims(opt[:subplot])[1]), + zx = (:y, ylims(opt[:subplot])[2]), + ), + get(opt, :series_projection, :xz), + ) + push!(series_opt, + "mesh" => nothing, + "mesh/check" => false, + "mesh/cols" => size(opt[:z], 1), + "mesh/rows" => size(opt[:z], 2), + "patch type" => "line", + "point meta" => "rawz", + "$proj_letter filter/.code" => "\\def\\pgfmathresult{$lim_value}" + ) + else + push!( + series_opt, + "contour prepared" => PGFPlotsX.Options("labels" => opt[:contour_labels]), + ) + end args = pgfx_series_arguments(series, opt) series_plot = series_func(series_opt, PGFPlotsX.Table(Contour.contours(args..., opt[:levels]))) push!(axis, series_plot) diff --git a/src/utils.jl b/src/utils.jl index 81779dd3..6b75182e 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -531,7 +531,7 @@ function get_colorgradient(series::Series) st = series[:seriestype] if st in (:surface, :heatmap) || isfilledcontour(series) series[:fillcolor] - elseif st in (:contour, :wireframe) + elseif st in (:contour, :wireframe, :contour3d) series[:linecolor] elseif series[:marker_z] !== nothing series[:markercolor]