Skip to content

Commit 5ab274d

Browse files
authored
fix spy {x,y}flip (#374)
1 parent b379a32 commit 5ab274d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+332
-255
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
version:
2121
- '1.6' # latest LTS
2222
- '1'
23-
- '~1.10.0-0' # upcoming julia version, next `rc`
23+
- '~1.11.0-0' # upcoming julia version, next `rc`
2424
experimental:
2525
- false
2626
os: [ubuntu-latest]

src/interface/heatmap.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ function heatmap(
178178
labels,
179179
height,
180180
width,
181+
margin,
181182
colorbar_lim = (mi, ma),
182183
colormap = callback,
183184
min_height = 1,

src/interface/spy.jl

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
8592
function 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
154176
end
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)

src/plot.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ function Plot(
196196
height = something(height :auto ? displaysize(stdout)[1] - 6 - (isempty(title) ? 0 : 1) : height, DEFAULT_HEIGHT[])
197197
width = something(width :auto ? displaysize(stdout)[2] - 10 : width, DEFAULT_WIDTH[])
198198

199-
(visible = width > 0) && (width = max(width, min_width))
199+
(visible = width 0) && (width = max(width, min_width))
200200
height = max(height, min_height)
201201

202202
x, y, z = validate_input(x, y, z)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
┌─────┐
2-
1 │⠀⠀⠀⠀⠀│ > 0
3-
0 │⠀⠀⠀⠀⠀│ < 0
2+
0 │⠀⠀⠀⠀⠀│ > 0
3+
1 │⠀⠀⠀⠀⠀│ < 0
44
└─────┘
5-
⠀1⠀⠀⠀0⠀
5+
⠀0⠀⠀⠀1⠀
66
⠀0 ≠ 0⠀
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
┌─────┐
2-
1 │⠀│ > 0
3-
10 ││ < 0
2+
1 │⠀⠐⠁│ > 0
3+
10 ││ < 0
44
└─────┘
55
⠀1⠀⠀10⠀
66
⠀14 ≠ 0
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
┌────────┐
2-
1 │⠀⠀│ > 0
3-
 │⠀⠀⠀│ < 0
4-
10 │⠂⠈⠈⠂⠐│ 
2+
1 │⠀⠆⠀│ > 0
3+
 │⡀⠀│ < 0
4+
10 │⠈⠀⠀⠈│ 
55
└────────┘
66
⠀1⠀⠀⠀⠀⠀15⠀
77
⠀⠀26 ≠ 0⠀⠀
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
┌─────┐
2-
1 │⢄⠀│ > 0
3-
 ││ < 0
4-
 ││ 
5-
15 ││ 
2+
1 │⠄⠐⢄⠀│ > 0
3+
 │⡁⡀⡄│ < 0
4+
 │⢀⠂│ 
5+
15 ││ 
66
└─────┘
77
⠀1⠀⠀10⠀
88
⠀26 ≠ 0

test/references_24/spy/default_2000x200.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
1 │⠀⠁⠀⠂⠀│ > 0
33
 │⠀⠀⠐⠀⠀│ < 0
44
 │⠠⠈⠌⡀⠰│ 
5-
 │⠀⠀⠄⠌│ 
5+
 │⠀⠀⠄⠌│ 
66
 │⠀⠀⢉⠁⠀│ 
77
 │⢈⠀⠂⠀⢄│ 
88
 │⠀⠢⠀⠀⠂│ 
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
┌──────────────────────────────────────────────────────────────────┐
2-
1 │⠀⠀⠀⢀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠄⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠈⠀⠀⠀⠀⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ > 0
3-
 │⠀⠀⠀⠀⠀⠀⠀⠠⠀⠀⠈⠂⠀⠀⠀⠀⠀⠀⠀⠀⠑⠀⢀⠀⠀⠂⠀⠠⠀⠠⠀⠀⠀⠀⠈⡀⠀⠀⠀⠁⠀⠀⠁⢀⠀⠀⠀⠀⠀⠀⠀⠀⠃⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⢀│ < 0
4-
192 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠈⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠄⠁⠀⠀⠄⠀⠀⠄⠀⠀⠀⠀⢀⠀⠀⠀⠀⠉⠀⠀⠀⠀⠂⠀⠀⠑⠀│ 
2+
1 │⠀⠀⠀⢀⠀⡀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠂⠀⠀⠀⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠄⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠈⠀⠀⠀⠀⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ > 0
3+
 │⠀⠀⠀⠀⠀⠀⠀⠠⠀⠀⠂⠀⠀⠀⠀⠀⠀⠀⠀⠑⠀⢀⠀⠀⠂⠀⠠⠀⠠⠀⠀⠀⠀⠈⡀⠀⠀⠀⠁⠀⠀⠁⢀⠀⠀⠀⠀⠀⠀⠀⠀⠃⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⢀│ < 0
4+
192 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠈⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠄⠁⠀⠀⠀⠀⠀⠄⠀⠀⠀⠀⢀⠀⠀⠀⠀⠉⠀⠀⠀⠀⠂⠀⠀⠑⠀│ 
55
└──────────────────────────────────────────────────────────────────┘
66
⠀1⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀1 982⠀
77
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀52 ≠ 0⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

0 commit comments

Comments
 (0)