Add :mesh3d seriesstyle for PyPlot backend

via `Poly3DCollection`.
This commit is contained in:
Lukas Hauertmann 2021-09-21 11:17:44 +02:00
parent 0cd81243ad
commit c9d8ac1721
2 changed files with 23 additions and 0 deletions

View File

@ -777,6 +777,7 @@ const _pyplot_attr = merge_with_base_supported([
:tick_direction, :tick_direction,
:camera, :camera,
:contour_labels, :contour_labels,
:connections
]) ])
const _pyplot_seriestype = [ const _pyplot_seriestype = [
:path, :path,
@ -793,6 +794,7 @@ const _pyplot_seriestype = [
:contour3d, :contour3d,
:path3d, :path3d,
:scatter3d, :scatter3d,
:mesh3d,
:surface, :surface,
:wireframe, :wireframe,
] ]

View File

@ -698,6 +698,27 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
end end
end end
if st == :mesh3d
if series[:connections] isa AbstractVector{<:AbstractVector{Int}}
polygons = broadcast(inds -> broadcast(i -> [x[i], y[i], z[i]], inds), series[:connections])
col = mplot3d.art3d.Poly3DCollection(polygons;
linewidths = py_thickness_scale(plt, series[:linewidth]),
edgecolor = py_color(get_linecolor(series)),
facecolor = py_color(series[:fillcolor]),
alpha = get_fillalpha(series),
zorder = series[:series_plotindex]
)
handle = ax."add_collection3d"(col)
# Fix for handle: https://stackoverflow.com/questions/54994600/pyplot-legend-poly3dcollection-object-has-no-attribute-edgecolors2d
# It seems there aren't two different alpha values for edge and face
handle._facecolors2d = py_color(series[:fillcolor])
handle._edgecolors2d = py_color(get_linecolor(series))
push!(handles, handle)
else
error("Unsupported type $(typeof(series[:connections])) for keyword `:connections`.")
end
end
if st == :image if st == :image
xmin, xmax = ignorenan_extrema(series[:x]) xmin, xmax = ignorenan_extrema(series[:x])
ymin, ymax = ignorenan_extrema(series[:y]) ymin, ymax = ignorenan_extrema(series[:y])