Plots.findnz for sparse and non-sparse matrices
This commit is contained in:
parent
0ee1d867c9
commit
43f31cbc98
@ -10,7 +10,7 @@ using Reexport
|
||||
|
||||
import GeometryTypes
|
||||
using Dates, Printf, Statistics, Base64, LinearAlgebra, Random
|
||||
import SparseArrays: findnz
|
||||
import SparseArrays: AbstractSparseMatrix, findnz
|
||||
|
||||
using FFMPEG
|
||||
|
||||
|
||||
@ -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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user