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,26 +699,37 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
end end
if st == :mesh3d if st == :mesh3d
if series[:connections] isa AbstractVector{<:AbstractVector{Int}} polygons = if series[:connections] isa AbstractVector{<:AbstractVector{Int}}
polygons = broadcast(inds -> broadcast(i -> [x[i], y[i], z[i]], inds), series[:connections]) broadcast(inds -> broadcast(i -> [x[i], y[i], z[i]], inds), series[:connections])
col = mplot3d.art3d.Poly3DCollection(polygons; elseif series[:connections] isa NTuple{3,<:AbstractVector{Int}}
linewidths = py_thickness_scale(plt, series[:linewidth]), ci, cj, ck = series[:connections]
edgecolor = py_color(get_linecolor(series)), if !(length(ci) == length(cj) == length(ck))
facecolor = py_color(series[:fillcolor]), throw(
alpha = get_fillalpha(series), ArgumentError("Argument connections must consist of equally sized arrays."),
zorder = series[:series_plotindex] )
) end
handle = ax."add_collection3d"(col) broadcast(j -> broadcast(i -> [x[i], y[i], z[i]], [ci[j]+1, cj[j]+1, ck[j]+1]), eachindex(ci))
# 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 else
error("Unsupported type $(typeof(series[:connections])) for keyword `:connections`.") throw(
ArgumentError("Unsupported `:connections` type $(typeof(series[:connections])) for seriestype=$st"),
)
end end
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)
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])