|
| 1 | +# helper |
| 2 | +padlims(v; frac=0.10) = begin |
| 3 | + vmin, vmax = extrema(v) |
| 4 | + span = max(vmax - vmin, eps()) |
| 5 | + (vmin - frac*span, vmax + frac*span) |
| 6 | +end |
| 7 | + |
| 8 | +function plot_weights(ws, inds; |
| 9 | + size=(640, 480), dpi=300, |
| 10 | + guidefs=20, tickfs=14, legendfs=16, |
| 11 | + grid=:y, |
| 12 | + margins=(left=30, right=40, bottom=30, top=20)) |
| 13 | + |
| 14 | + perm = sortperm(ws) |
| 15 | + s = ws[perm] |
| 16 | + x = collect(eachindex(s)) |
| 17 | + m = in(Set(inds)).(perm) |
| 18 | + |
| 19 | + # ensure margins are AbsoluteLength in px (avoids Int + AbsoluteLength conflicts) |
| 20 | + lp = margins.left * Plots.px |
| 21 | + rp = margins.right * Plots.px |
| 22 | + bp = margins.bottom* Plots.px |
| 23 | + tp = margins.top * Plots.px |
| 24 | + |
| 25 | + plt = plot(size=size, dpi=dpi, grid=grid, framestyle=:box, |
| 26 | + left_margin=lp, right_margin=rp, |
| 27 | + bottom_margin=bp, top_margin=tp, |
| 28 | + xguidefont=font(guidefs), yguidefont=font(guidefs), |
| 29 | + xtickfont=font(tickfs), ytickfont=font(tickfs), |
| 30 | + legendfont=font(legendfs)) |
| 31 | + |
| 32 | + scatter!(plt, x, s; |
| 33 | + color=:gray, alpha=0.25, |
| 34 | + marker=:circle, markersize=8, markerstrokewidth=0, |
| 35 | + label="All", |
| 36 | + xlabel="Sorted element indices", |
| 37 | + ylabel="Weights", |
| 38 | + ylims=padlims(s)) |
| 39 | + |
| 40 | + if any(m) |
| 41 | + scatter!(plt, x[m], s[m]; |
| 42 | + color=:red, marker=:utriangle, |
| 43 | + markersize=10, markerstrokewidth=0, |
| 44 | + label="Selected") |
| 45 | + else |
| 46 | + plot!(plt, NaN, NaN; label="Selected") |
| 47 | + end |
| 48 | + |
| 49 | + return plt |
| 50 | +end |
| 51 | + |
0 commit comments