@@ -82,6 +82,13 @@ _strict_non_zeros(rows, cols, vals) =
8282 rows[I], cols[I], vals[I]
8383 end
8484
85+ _findnz (A:: AbstractMatrix ) =
86+ let I = findall (! iszero, A)
87+ getindex .(I, 1 ), getindex .(I, 2 ), A[I]
88+ end
89+
90+ _findnz (A:: AbstractSparseMatrix ) = findnz (A)
91+
8592function spy (
8693 nrow:: Integer ,
8794 ncol:: Integer ,
@@ -99,6 +106,8 @@ function spy(
99106 canvas:: Type{<:Canvas} = KEYWORDS. canvas,
100107 fix_ar:: Bool = KEYWORDS. fix_ar,
101108 show_zeros:: Bool = false ,
109+ xflip:: Bool = false ,
110+ yflip:: Bool = true ,
102111 kw... ,
103112)
104113 pkw, okw = split_plot_kw (kw)
@@ -120,15 +129,33 @@ function spy(
120129 extra_cols = 6 ,
121130 )
122131
123- can = canvas (height, width; height = 1.0 + nrow, width = 1.0 + ncol)
124- plot = Plot (can; margin, padding, pkw... )
132+ ylim = [1 , nrow]
133+ xlim = [1 , ncol]
134+
135+ plot = Plot (
136+ xlim,
137+ ylim,
138+ nothing ,
139+ canvas;
140+ ylim,
141+ xlim,
142+ yflip,
143+ xflip,
144+ height,
145+ width,
146+ margin,
147+ padding,
148+ grid = false ,
149+ canvas_kw = (; height = 1.0 + nrow, width = 1.0 + ncol),
150+ pkw... ,
151+ )
125152
126153 if color ≢ :auto
127- points! (plot, cols, nrow + 1 .- rows; color)
154+ points! (plot, cols, rows; color)
128155 label! (plot, :r , 1 , show_zeros ? " ⩵ 0" : " ≠ 0" , color)
129156 else
130157 if show_zeros
131- points! (plot, cols, nrow + 1 .- rows; color = :green )
158+ points! (plot, cols, rows; color = :green )
132159 label! (plot, :r , 1 , " ⩵ 0" , :green )
133160 else
134161 pos_idx = vals .> 0
@@ -137,25 +164,13 @@ function spy(
137164 pos_rows = rows[pos_idx]
138165 neg_cols = cols[neg_idx]
139166 neg_rows = rows[neg_idx]
140- points! (plot, pos_cols, nrow + 1 .- pos_rows; color = :red )
141- points! (plot, neg_cols, nrow + 1 .- neg_rows; color = :blue )
167+ points! (plot, pos_cols, pos_rows; color = :red )
168+ points! (plot, neg_cols, neg_rows; color = :blue )
142169 label! (plot, :r , 1 , " > 0" , :red )
143170 label! (plot, :r , 2 , " < 0" , :blue )
144171 end
145172 end
146- bc = BORDER_COLOR[]
147- label! (plot, :l , 1 , " 1" , bc)
148- label! (plot, :l , nrows (plot. graphics), nice_repr (nrow, plot), bc)
149- label! (plot, :bl , " 1" , bc)
150- label! (plot, :br , nice_repr (ncol, plot), bc)
151173 isempty (xlabel (plot)) &&
152174 xlabel! (plot, nice_repr (length (vals), plot) * (show_zeros ? " ⩵ 0" : " ≠ 0" ))
153175 plot
154176end
155-
156- _findnz (A:: AbstractMatrix ) =
157- let I = findall (! iszero, A)
158- getindex .(I, 1 ), getindex .(I, 2 ), A[I]
159- end
160-
161- _findnz (A:: AbstractSparseMatrix ) = findnz (A)
0 commit comments