From 0628fb9dc353959adc2fbfb54c639f303372c688 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 19 Feb 2021 18:59:47 +0100 Subject: [PATCH 1/6] enable transparency for surface with GR --- src/backends/gr.jl | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 227a122f..b6fc8135 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1732,15 +1732,12 @@ function gr_draw_contour(series, x, y, z, clims) end function gr_draw_surface(series, x, y, z, clims) + gr_set_transparency(get_fillcolor(series), get_fillalpha(series)) if series[:seriestype] === :surface if length(x) == length(y) == length(z) x, y, z = GR.gridit(x, y, z, 200, 200) end - try - GR.gr3.surface(x, y, z, GR.OPTION_COLORED_MESH) - catch - GR.surface(x, y, z, GR.OPTION_COLORED_MESH) - end + GR.surface(x, y, z, GR.OPTION_COLORED_MESH) else # wireframe GR.setfillcolorind(0) GR.surface(x, y, z, GR.OPTION_FILLED_MESH) From d59f6c96d535e809ce83a99738545a898a68c250 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 19 Feb 2021 20:26:18 +0100 Subject: [PATCH 2/6] fix surface for pyplot --- src/backends/pyplot.jl | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 8dc2a4ae..f65460e5 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -924,7 +924,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) kw[:spacing] = "proportional" if RecipesPipeline.is3d(sp) || ispolar(sp) - cbax = fig."add_axes"([0.9, 0.1, 0.03, 0.8]) + cbax = fig."add_axes"([0.9, 0.1, 0.03, 0.8], label=string("cbar", sp[:subplot_index])) cb = fig."colorbar"(handle; cax=cbax, kw...) else # divider approach works only with 2d plots @@ -949,7 +949,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) colorbar_orientation="horizontal" end - cbax = divider.append_axes(colorbar_position, size="5%", pad=colorbar_pad) # Reasonable value works most of the usecases + cbax = divider.append_axes(colorbar_position, size="5%", pad=colorbar_pad, label=string("cbar", sp[:subplot_index])) # Reasonable value works most of the usecases cb = fig."colorbar"(handle; cax=cbax, orientation = colorbar_orientation, kw...) if sp[:colorbar] == :left @@ -1257,11 +1257,10 @@ function _update_min_padding!(sp::Subplot{PyPlotBackend}) # optionally add the width of colorbar labels and colorbar to rightpad - # if haskey(sp.attr, :cbar_ax) - # bb = py_bbox(sp.attr[:cbar_handle]."ax"."get_yticklabels"()) - # sp.attr[:cbar_width] = width(bb) + (sp[:colorbar_title] == "" ? 0px : 30px) - # rightpad = rightpad + sp.attr[:cbar_width] - # end + if RecipesPipeline.is3d(sp) || haskey(sp.attr, :cbar_ax) + bb = py_bbox(sp.attr[:cbar_handle]."ax"."get_yticklabels"()) + sp.attr[:cbar_width] = width(bb) + (sp[:colorbar_title] == "" ? 0px : 30px) + end # add in the user-specified margin leftpad += sp[:left_margin] From 100da5ccae266c258174cd24a254650b49d969fd Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 19 Feb 2021 20:59:48 +0100 Subject: [PATCH 3/6] fix fillalpha for surface on pyplot --- src/backends/pyplot.jl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index f65460e5..83899620 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -205,9 +205,15 @@ function fix_xy_lengths!(plt::Plot{PyPlotBackend}, series::Series) end end -py_linecolormap(series::Series) = py_colormap(series[:linecolor]) -py_markercolormap(series::Series) = py_colormap(series[:markercolor]) -py_fillcolormap(series::Series) = py_colormap(series[:fillcolor]) +function py_linecolormap(series::Series) + py_colormap(cgrad(get_linecolor(series), alpha=get_linealpha(series))) +end +function py_markercolormap(series::Series) + py_colormap(cgrad(get_markercolor(series), alpha=get_markeralpha(series))) +end +function py_fillcolormap(series::Series) + py_colormap(cgrad(get_fillcolor(series), alpha=get_fillalpha(series))) +end # --------------------------------------------------------------------------- From 2e2f7044e2f873bb1a39bb31214bab7cbb26c202 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 19 Feb 2021 21:20:51 +0100 Subject: [PATCH 4/6] fix surface on pgfplotsx --- src/backends/pgfplotsx.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 9bf2a6c9..063c838d 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -836,7 +836,7 @@ function pgfx_colormap(v::Vector{<:Colorant}) end function pgfx_colormap(cg::ColorGradient) join(map(1:length(cg)) do i - @sprintf("rgb(%.8fcm)=(%.8f,%.8f,%.8f)", cg.values[i], red(cg.colors[i]), green(cg.colors[i]), blue(cg.colors[i])) + @sprintf("rgb(%.8f)=(%.8f,%.8f,%.8f)", cg.values[i], red(cg.colors[i]), green(cg.colors[i]), blue(cg.colors[i])) end, "\n") end From e8437d76fd8c6b1316874c6a6b5404e5f9318eaa Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 19 Feb 2021 21:22:57 +0100 Subject: [PATCH 5/6] fix fillalpha for surface on pgfplotsx --- src/backends/pgfplotsx.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 063c838d..f2e09073 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -497,6 +497,7 @@ function pgfx_add_series!(::Val{:surface}, axis, series_opt, series, series_func "mesh/rows" => length(opt[:x]), "mesh/cols" => length(opt[:y]), "z buffer" => "sort", + "opacity" => get_fillalpha(series), ) pgfx_add_series!(axis, series_opt, series, series_func, opt) end From 0a6edd5d60c79026ee91104a0aa1a8a302a415e6 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 19 Feb 2021 22:08:02 +0100 Subject: [PATCH 6/6] fix gr test example --- src/backends/gr.jl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index b6fc8135..56693c00 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1732,12 +1732,19 @@ function gr_draw_contour(series, x, y, z, clims) end function gr_draw_surface(series, x, y, z, clims) - gr_set_transparency(get_fillcolor(series), get_fillalpha(series)) + if series[:seriestype] === :surface + fillalpha = get_fillalpha(series) + fillcolor = get_fillcolor(series) if length(x) == length(y) == length(z) x, y, z = GR.gridit(x, y, z, 200, 200) end - GR.surface(x, y, z, GR.OPTION_COLORED_MESH) + if (!isnothing(fillalpha) && fillalpha < 1) || alpha(first(fillcolor)) < 1 + gr_set_transparency(fillcolor, fillalpha) + GR.surface(x, y, z, GR.OPTION_COLORED_MESH) + else + GR.gr3.surface(x, y, z, GR.OPTION_COLORED_MESH) + end else # wireframe GR.setfillcolorind(0) GR.surface(x, y, z, GR.OPTION_FILLED_MESH)