Skip to content

Instantly share code, notes, and snippets.

@danscr
Last active November 19, 2019 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danscr/539f0840594b628335f7ebcc5ac19609 to your computer and use it in GitHub Desktop.
Save danscr/539f0840594b628335f7ebcc5ac19609 to your computer and use it in GitHub Desktop.
MWE of voxel plot using PGFPlotsX
using PGFPlotsX
#array with color mixture ratio
lam = rand(4,5,8)
# filter out values with less than 10%
s = sum(lam .> 0.1)
#rearrange to get each array position and color in vector format
xyz = Array{Float64}(undef,s,3)
col = Array{Float64}(undef,s)
let
l = 1
for i in 1:4
for j in 1:5
for k in 1:8
if Λ[i,j,k] > 0.1
xyz[l,1] = i
xyz[l,2] = j
xyz[l,3] = k
col[l] = lam[i,j,k]
l += 1
end
end
end
end
end
#scale position vectors
xyz *= 0.1
p = @pgf Axis({
view=(95,5),
"axis equal"
},
(Plot3({only_marks,
mark="cube*",
mark_size="1mm",
fill="black!$(Int(floor(col[i]*100)))!red"},
Table(
x=xyz[i,1],
y=xyz[i,2],
z=xyz[i,3])) for i in 1:s)...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment