Add support for only-triangle syntax for :connections kw

for PyPlot
This commit is contained in:
Lukas Hauertmann 2021-09-21 13:35:03 +02:00
parent 20c528879d
commit 3051adfa91

View File

@ -699,9 +699,22 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
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;
polygons = if series[:connections] isa AbstractVector{<:AbstractVector{Int}}
broadcast(inds -> broadcast(i -> [x[i], y[i], z[i]], inds), series[:connections])
elseif series[:connections] isa NTuple{3,<:AbstractVector{Int}}
ci, cj, ck = series[:connections]
if !(length(ci) == length(cj) == length(ck))
throw(
ArgumentError("Argument connections must consist of equally sized arrays."),
)
end
broadcast(j -> broadcast(i -> [x[i], y[i], z[i]], [ci[j]+1, cj[j]+1, ck[j]+1]), eachindex(ci))
else
throw(
ArgumentError("Unsupported `:connections` type $(typeof(series[:connections])) for seriestype=$st"),
)
end
col = mplot3d.art3d.Poly3DCollection(polygons,
linewidths = py_thickness_scale(plt, series[:linewidth]),
edgecolor = py_color(get_linecolor(series)),
facecolor = py_color(series[:fillcolor]),
@ -714,11 +727,9 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
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
xmin, xmax = ignorenan_extrema(series[:x])
ymin, ymax = ignorenan_extrema(series[:y])