Problem
Hi, I’m having a hard time figuring out how to do the following, though I’m sure there must be some “easy” solution that I just cannot find.
I have a 3-dimensional array of booleans and I’d like to see the “contours” of it (i.e. when it changes from false
to true
) along the first two-dimensions and how such contours change along the third.
Something in the lines of:
using Plots
pyplot()
V = falses(20, 10, 3);
[V[i, j, k] = i/20 + j/10 - k/3 > 0 for i in 1:20, j in 1:10, k in 1:3]
pl = plot(V[:, :, 1], st = :contour, levels = 1)
plot!(pl, V[:, :, 2], st = :contour, levels = 1)
plot!(pl, V[:, :, 3], st = :contour, levels = 1)
I have a couple of issues with the above plot:
- Each contour plot actually includes 2 contour lines and I’d like that to be only 1
- I’d like to label each contour line for its
k
-th level - It seems clunky and excessive
Imperfect solutions
One option I could do is change the value of V
to match the k
-th level, something like:
VV = [V[i, j, k].*k for i in 1:20, j in 1:10, k in 1:3]
pl = plot(VV[:, :, 1], st = :contour, levels = 1)
plot!(pl, VV[:, :, 2], st = :contour, levels = 1)
plot!(pl, VV[:, :, 3], st = :contour, levels = 1)
however that doesn’t solve problem 1 and it looks like an especially clunky workaround.
A somewhat better option could be to just define the sum and do the contour plot of that.
VVV = sum(V, dims = 3)
plot(VVV[:, :], st = :contour, levels = 2)
This works in this simple example but in my actual use case the levels might actually intersect and I’d still like to know which level goes where.
Thanks a lot in advance for any help