Merge pull request #2755 from jamblejoe/fix/spy

Plots.findnz for sparse and non-sparse matrices
This commit is contained in:
Daniel Schwabeneder 2020-06-04 13:31:30 +02:00 committed by GitHub
commit ad4a00c055
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -10,7 +10,7 @@ using Reexport
import GeometryTypes
using Dates, Printf, Statistics, Base64, LinearAlgebra, Random
import SparseArrays: findnz
import SparseArrays: AbstractSparseMatrix, findnz
using FFMPEG

View File

@ -1415,7 +1415,7 @@ end
@recipe function f(::Type{Val{:spy}}, x, y, z)
yflip := true
aspect_ratio := 1
rs, cs, zs = findnz(z.surf)
rs, cs, zs = Plots.findnz(z.surf)
xlims := ignorenan_extrema(cs)
ylims := ignorenan_extrema(rs)
if plotattributes[:markershape] == :none
@ -1435,6 +1435,18 @@ end
()
end
Plots.findnz(A::AbstractSparseMatrix) = findnz(A)
# fallback function for finding non-zero elements of non-sparse matrices
function Plots.findnz(A::AbstractMatrix)
keysnz = findall(!iszero, A)
rs = [k[1] for k in keysnz]
cs = [k[2] for k in keysnz]
zs = A[keysnz]
rs, cs, zs
end
# -------------------------------------------------
"Adds ax+b... straight line over the current plot, without changing the axis limits"