I have a Grid
type, and I have a way to plot it in terms of an image (Array{RBGA{...}, 2}
), so I define the following user recipe:
using Plots
using Plots: RGBA
using RecipesBase
using OffsetArrays
struct Grid
x::OffsetArray{Bool, 2, Array{Bool, 2}}
end
@recipe function f(s::Grid)
# TODO use :seriescolor and :seriesalpha in plotattributes
full = RGBA(0.0, 0.0, 1.0, 0.5)
empty = RGBA(0.0, 0.0, 0.0, 0.0)
axs = axes(s.x)
f = first.(axs) .- 0.5
l = last.(axs) .+ 0.5
_range(start, step, stop) = start:step:stop
extents = map(_range, f, [1.0, 1.0], l)
(d1, d2) = extents
d1, d2, ifelse.(transpose(s.x.parent), full, empty)
end
a = fill(false, (-5:5, 0:10))
a[:] .= rand(Bool, 11, 11)[:]
plot(Grid(a))
which produces
What’s a good way to handle e.g. plot(Grid(a), color=:red, alpha=0.2)
(which would correspond to full = RGBA(1.0, 0.0, 1.0, 0.2)
) ? I imagine roughly two strategies:
- handle the conversion to
RGBA
in my recipe - find some plot type that would handle that conversion for me