Merge pull request #3313 from daschw/surface

Surface fixes
This commit is contained in:
Daniel Schwabeneder 2021-02-19 22:35:31 +01:00 committed by GitHub
commit 1ef15934cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 14 deletions

View File

@ -1732,14 +1732,18 @@ function gr_draw_contour(series, x, y, z, clims)
end
function gr_draw_surface(series, x, y, z, clims)
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
try
GR.gr3.surface(x, y, z, GR.OPTION_COLORED_MESH)
catch
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)

View File

@ -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
@ -836,7 +837,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

View File

@ -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
# ---------------------------------------------------------------------------
@ -924,7 +930,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 +955,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 +1263,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]